-
Notifications
You must be signed in to change notification settings - Fork 27
93 lines (85 loc) · 3.71 KB
/
add-depr-ticket-to-depr-board.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
88
89
90
91
92
93
# This workflow runs when an issue is created; it checks if the issue is either:
# - labelled "DEPR"
# - title starts with "[DEPR]"
# - body starts with "Proposal Date" (this is the first template field)
# If so, adds the DEPR label, adds it to the
# DEPR board in the default column, and a message is posted to the
# #depr-slash-n-burn slack channel
# Note: The "DEPR" label is NOT auto-applied to all tickets created using the
# `depr-ticket.yml` template, because only those with write access can add the
# label. So additionally, the template inserts [DEPR] at the beginning. So, this
# automation is shakily governed by hoping users do not remove that phrase.
name: Add newly created DEPR issues to the DEPR project board
on:
# This action is meant to be used from other actions.
# https://docs.github.com/en/actions/learn-github-actions/reusing-workflows
workflow_call:
secrets:
GITHUB_APP_ID:
required: true
GITHUB_APP_PRIVATE_KEY:
required: true
SLACK_BOT_TOKEN:
required: true
jobs:
# First parse issue title and add label, if it doesn't have it already bc only
# repo members can add the label, even tho it's defined in the template >:(
add_label:
runs-on: ubuntu-latest
# This is defined on both jobs - so need to change x2 if changing this.
if: ${{ (contains(github.event.issue.title, '[DEPR]') || startsWith(github.event.issue.body, 'Proposal Date')) && !contains(github.event.issue.labels.*.name, 'DEPR') }}
steps:
- name: apply DEPR label
uses: actions-ecosystem/action-add-labels@v1
with:
labels: DEPR
# Add the ticket to the DEPR board and notify in Slack
add_and_notify:
runs-on: ubuntu-latest
if: ${{ contains(github.event.issue.title, '[DEPR]') || startsWith(github.event.issue.body, 'Proposal Date') || contains(github.event.issue.labels.*.name, 'DEPR') }}
steps:
# Generate a token from org-level GitHub App because projects (beta)
# are defined at the org level
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.GITHUB_APP_ID }}
private_key: ${{ secrets.GITHUB_APP_PRIVATE_KEY }}
- name: Get DEPR project ID
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
ORGANIZATION: openedx
PROJECT_NUMBER: 9
run: |
gh api graphql -f query='
query($org: String!, $number: Int!) {
organization(login: $org){
projectV2(number: $number) {
id
}
}
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV
- name: Add DEPR issue to project
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
ISSUE_ID: ${{ github.event.issue.node_id }}
run: |
item_id="$( gh api graphql -f query='
mutation($project:ID!, $issue:ID!) {
addProjectV2ItemById(input: {projectId: $project, contentId: $issue}) {
item {
id
}
}
}' -f project=$PROJECT_ID -f issue=$ISSUE_ID --jq '.data.addProjectV2ItemById.item.id')"
- name: Alert in Slack
id: slack
uses: slackapi/[email protected]
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
channel: "CGB0S3L12"
text: "Incoming DEPR ticket: ${{ github.event.issue.title }}\nAuthor: ${{ github.event.issue.user.login }}\nURL: ${{ github.event.issue.html_url }}"