Action

Linear Multiple Issues

Posted by tom.foutz, Last update 3 months ago

Create Multiple Issues in LInear

By Thomas Foutz
2024-08-13

Steps

  • script

    var credential = Credential.create("Linear.app", "Insert Linear.app token generated on Linear.app account page.");
    
    credential.addTextField("apptoken", "App Token");
    credential.addTextField("teamid", "Team ID");
    credential.authorize();
    
    var appToken = credential.getValue("apptoken");
    var teamId = credential.getValue("teamid");
    
    if (draft.content.length == 0) {
        alert("Draft is blank");
        context.cancel("Draft was blank");
    } else {
        var lines = draft.content.split("\n");
    
        // Iterate over each line in the draft and create a new issue
        for (var i = 0; i < lines.length; i++) {
            let issueTitle = lines[i].trim();
    
            if (issueTitle.length > 0) {
                var variables = {
                    "title": issueTitle,
                    "description": "",
                    "teamId": teamId
                };
    
                // Prepare GraphQL query for creating the issue
                var graphqlQuery = `
                mutation IssueCreate($title: String!, $teamId: String!, $description: String) {
                    issueCreate(input: { title: $title, description: $description, teamId: $teamId }) {
                        success
                        issue {
                            identifier
                            url
                        }
                    }
                }`;
    
                // Create issue
                var http = HTTP.create();
                var response = http.request({
                    "url": "https://api.linear.app/graphql",
                    "method": "POST",
                    "encoding": "json",
                    "data": {
                        "query": graphqlQuery,
                        "variables": variables
                    },
                    "headers": {
                        "Authorization": appToken,
                        "Content-Type": "application/json"
                    }
                });
    
                if (response.statusCode != 200 && response.statusCode != 202) {
                    console.log("Failed to create issue: " + response.statusCode);
                } else {
                    console.log("Issue created successfully: " + response.responseText);
                }
            }
        }
    }
    

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.