forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 3
87 lines (75 loc) · 3.58 KB
/
move-new-issues-to-correct-docs-repo.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Move new issues to correct docs repo
# **What it does**: If anyone creates an issue in the docs-internal repo for the engineering team or the content team, move that issue and notify the author
# **Why we have it**: We don't want engineering or content issues in the docs-internal repo
# **Who does it impact**: GitHub staff.
on:
issues:
types:
- opened
- transferred
- reopened
jobs:
transfer_issue:
runs-on: ubuntu-latest
continue-on-error: true
if: github.repository == 'github/docs-internal'
steps:
- id: move_to_correct_repo
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
env:
TEAM_ENGINEERING_REPO: ${{ secrets.TEAM_ENGINEERING_REPO }}
TEAM_CONTENT_REPO: ${{ secrets.TEAM_CONTENT_REPO }}
with:
github-token: ${{ secrets.DOCUBOT_READORG_REPO_WORKFLOW_SCOPES }}
script: |
const issueNo = context.issue.number
const owner = 'github'
const originalRepo = 'docs-internal'
// See if the engineering label is present.
const engineeringLabel = context.payload.issue.labels.find(label => label.name === 'engineering')
// Transfer engineering issues to the engineering repo and everything else to the Docs Content repo
let correctRepo = process.env.TEAM_CONTENT_REPO
if (engineeringLabel) {
correctRepo = process.env.TEAM_ENGINEERING_REPO
}
const correctRepoObject = await github.repos.get({
owner: owner,
repo: correctRepo
})
// Post a comment in the docs-internal issue
await github.issues.createComment({
owner: owner,
repo: originalRepo,
issue_number: issueNo,
body: `👋 You opened this issue in '${context.repo.repo}'. Moving forward, we're asking that folks create new issues in the following repositories instead:\n- For issues with the docs site, please submit to the [${process.env.TEAM_ENGINEERING_REPO}](/${owner}/${process.env.TEAM_ENGINEERING_REPO}) repo.\n- For all new content issues, please submit to the [${process.env.TEAM_CONTENT_REPO}](/${owner}/${process.env.TEAM_CONTENT_REPO}) repo.\n\nWe will transfer this issue for you!`
})
// Transfer the issue to the correct repo
const issueNodeId = context.payload.issue.node_id
const correctRepositoryNodeId = correctRepoObject.data.node_id
console.log(`Issue GraphQL Node ID: ${issueNodeId}`)
console.log(`Repository GraphQL Node ID: ${correctRepositoryNodeId}`)
const mutation = `mutation ($id: ID!, $repositoryId: ID!) {
transferIssue(input: {
issueId: $id,
repositoryId: $repositoryId
}) {
issue {
url,
number
}
}
}`
const variables = {
id: issueNodeId,
repositoryId: correctRepositoryNodeId
}
const graph = await github.graphql(mutation, variables)
console.log('GraphQL mutation result:\n' + JSON.stringify(graph))
// Add the same labels to the new issue
const newIssueNumber = graph.transferIssue.issue.number
await github.issues.addLabels({
owner: owner,
repo: correctRepo,
issue_number: newIssueNumber,
labels: context.payload.issue.labels.map(label => label.name),
})