Action

Linear Issue with Description

Posted by tom.foutz, Last update 3 months ago

Create an Issue in LInear with a Description

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 {
    
        // Extract title and body from the draft
        let issueTitle = draft.processTemplate("[[title]]");
        let issueDescription = draft.processTemplate("[[body]]");
    
        // Prepare GraphQL variables
        var variables = {
            "title": issueTitle,
            "description": issueDescription,
            "teamId": teamId
        };
    
        // Prepare GraphQL query
        var graphqlQuery = `
        mutation IssueCreate($title: String!, $teamId: String!, $description: String) {
            issueCreate(input: { title: $title, description: $description, teamId: $teamId }) {
                success
                issue {
                    identifier
                    url
                }
            }
        }`;
    
        // Create and send HTTP request
        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"
            }
        });
    
        console.log("Response: " + response.statusCode);
        if (response.statusCode != 200 && response.statusCode != 202) {
            context.fail("Failed to create issue in Linear.app: " + 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.