Created
January 19, 2022 16:40
-
-
Save degrammer/16dfeaab0335b0f56345e6f95e0c57c3 to your computer and use it in GitHub Desktop.
GitHub Linear slash command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
integration.event.on('/:componentName/webhook/issue_comment.created', async (ctx) => { | |
const { | |
data: { comment, repository, issue, installation }, | |
} = ctx.req.body.data; | |
const commentText = comment.body; | |
const isLinearCommand = commentText.match(/^\/linear/g).length > 0; | |
if (isLinearCommand) { | |
const linearClient = await integration.service.getSdk(ctx, 'popular-js-linear', ctx.req.body.installIds[0]); | |
const [titlePart, description] = commentText.split('\n'); | |
const title = titlePart.replace('/linear', ''); | |
console.log(title); | |
const teams = await linearClient.teams(); | |
const team = teams.nodes[0]; | |
if (team.id) { | |
const { _issue } = await linearClient.issueCreate({ teamId: team.id, title, description }); | |
const linearIssue = await linearClient.issue(_issue.id); | |
// Reply to GitHub that the issue was created on Linear | |
const issueBody = `Issue created: <a href="${linearIssue.url}" target="_blank">${linearIssue.identifier}</a>`; | |
const githubClient = await integration.service.getSdk(ctx, 'popular-js', ctx.req.body.installIds[0]); | |
const installationClient = await githubClient.installation(installation.id); | |
const { data: { html_url } } = await installationClient.rest.issues.createComment({ | |
owner: repository.owner.login, | |
repo: repository.name, | |
issue_number: issue.number, | |
body: issueBody, | |
}); | |
await linearClient.commentCreate({ issueId: _issue.id, body: `GitHub issue: ${html_url}` }); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment