|
| 1 | +const {Toolkit} = require('actions-toolkit'); |
| 2 | +const {withDefaults} = require('actions-toolkit/lib/graphql'); |
| 3 | + |
| 4 | +Toolkit.run(async tools => { |
| 5 | + // Re-authenticate with the correct secret. |
| 6 | + tools.github.graphql = withDefaults(process.env.GRAPHQL_TOKEN); |
| 7 | + |
| 8 | + // Ensure that the actor of the triggering action belongs to the core team |
| 9 | + const actorLogin = tools.context.actor; |
| 10 | + const teamResponse = await tools.github.graphql(` |
| 11 | + query { |
| 12 | + organization(login: "atom") { |
| 13 | + team(slug: "github-package") { |
| 14 | + members(first: 100) { |
| 15 | + nodes { |
| 16 | + login |
| 17 | + } |
| 18 | + } |
| 19 | + } |
| 20 | + } |
| 21 | + } |
| 22 | + `); |
| 23 | + if (!teamResponse.organization.team.members.nodes.some(node => node.login === actorLogin)) { |
| 24 | + tools.exit.neutral('User %s is not in the github-package team. Thanks for your contribution!', actorLogin); |
| 25 | + } |
| 26 | + |
| 27 | + // Identify the active release board and its "In progress" column |
| 28 | + const projectQuery = await tools.github.graphql(` |
| 29 | + query { |
| 30 | + repository(owner: "atom", name: "github") { |
| 31 | + projects( |
| 32 | + search: "Release" |
| 33 | + states: [OPEN] |
| 34 | + first: 1 |
| 35 | + orderBy: {field: CREATED_AT, direction: DESC} |
| 36 | + ) { |
| 37 | + nodes { |
| 38 | + id |
| 39 | + name |
| 40 | +
|
| 41 | + columns(first: 10) { |
| 42 | + nodes { |
| 43 | + id |
| 44 | + name |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + `); |
| 52 | + const project = projectQuery.repository.projects.nodes[0]; |
| 53 | + if (!project) { |
| 54 | + tools.exit.failure('No open project found with a name matching "Release".'); |
| 55 | + } |
| 56 | + const column = project.columns.nodes.find(node => node.name === 'In progress'); |
| 57 | + if (!column) { |
| 58 | + tools.exit.failure('No column found in the project %s with a name of exactly "In progress".', project.name); |
| 59 | + } |
| 60 | + |
| 61 | + // Add the issue/pull request to the sprint board |
| 62 | + await tools.github.graphql(` |
| 63 | + mutation ProjectCardAddition($columnID: ID!, $issueishID: ID!) { |
| 64 | + addProjectCard(input: {projectColumnId: $columnID, contentId: $issueishID}) { |
| 65 | + clientMutationId |
| 66 | + } |
| 67 | + } |
| 68 | + `, { |
| 69 | + columnID: column.id, |
| 70 | + issueishID: tools.context.event === 'issues' |
| 71 | + ? tools.context.payload.issue.node_id |
| 72 | + : tools.context.payload.pull_request.node_id, |
| 73 | + }); |
| 74 | + tools.exit.success('Added as a project card.'); |
| 75 | +}, { |
| 76 | + event: [ |
| 77 | + 'issues.assigned', |
| 78 | + 'pull_request.opened', |
| 79 | + 'pull_request.merged', |
| 80 | + 'pull_request.assigned', |
| 81 | + 'pull_request.reopened', |
| 82 | + ], |
| 83 | + secrets: ['GRAPHQL_TOKEN'], |
| 84 | +}); |
0 commit comments