-
Notifications
You must be signed in to change notification settings - Fork 6
121 lines (109 loc) · 4.04 KB
/
update-trending-base.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: Update epic trending field
on:
workflow_call:
secrets:
ACCESS_TOKEN:
description: GitHub Token
required: true
inputs:
project_owner:
description: GitHub Project Owner
type: string
default: 'grafana'
project_number:
description: GitHub Project Number
type: number
required: true
field_name:
description: GitHub Project Field Name
type: string
default: 'Trending'
jobs:
extract-trend:
name: Extract trend
runs-on: ubuntu-latest
outputs:
trend: ${{ steps.extract-trend.outputs.group1 }}
trend_id: ${{ steps.convert-trend.outputs.trend_id }}
error: ${{ steps.convert-trend.outputs.error }}
result: ${{ steps.convert-trend.outputs.result }}
steps:
- id: extract-trend
uses: kaisugi/action-regex-match@v1.0.1
with:
regex: '<!-- data key="trending" start -->([\s\S]*?)<!-- data end -->'
text: ${{ github.event.comment.body }}
- id: convert-trend
uses: actions/github-script@v7
if: ${{ steps.extract-trend.outputs.group1 != '' }}
with:
github-token: ${{ secrets.ACCESS_TOKEN }}
script: |
const variables = {
trend: `${{ steps.extract-trend.outputs.group1 }}`.trim(),
org: '${{ inputs.project_owner }}',
field_name: '${{ inputs.field_name }}',
project_number: ${{ inputs.project_number }}
};
const query = `
query($org: String!, $field_name: String!, $project_number:Int!, $trend: String!) {
organization(login: $org) {
projectV2(number: $project_number) {
field(name: $field_name) {
... on ProjectV2SingleSelectField {
options(names: [$trend]) {
id
}
}
}
}
}
}
`;
var result = {};
try {
result = await github.graphql(query, variables);
} catch (error) {
core.setOutput("error", error.message)
if (error.data) {
result = error.data;
core.setOutput("error", JSON.stringify(result))
}
}
core.setOutput("result", JSON.stringify(result));
const trend_id = result.organization.projectV2.field.options[0].id;
core.setOutput("trend_id", trend_id);
return;
update-trending:
name: Update epic trending field
runs-on: ubuntu-latest
needs: extract-trend
if: ${{ needs.extract-trend.outputs.trend_id != '' }}
steps:
- id: get-project-id
uses: monry/actions-get-project-id@v2
with:
# Personal Access Token that with `org:read` are granted.
github-token: ${{ secrets.ACCESS_TOKEN }}
# Owner name of project
project-owner: ${{ inputs.project_owner }}
# Number of project
#
# The project number is the number shown in the URL or list
# https://github.com/users/monry/projects/123
# ^^^
project-number: ${{ inputs.project_number }}
- id: get-item-id
uses: monry/actions-get-project-item-id@v2
with:
# Personal Access Token that with `repo` and `org:read` are granted.
github-token: ${{ secrets.ACCESS_TOKEN }}
project-id: ${{ steps.get-project-id.outputs.project-id }}
issue-id: ${{ github.event.issue.node_id }}
- uses: titoportas/update-project-fields@v0.1.0
with:
project-url: https://github.com/orgs/grafana/projects/${{ inputs.project_number }}
github-token: ${{ secrets.ACCESS_TOKEN }}
item-id: ${{ steps.get-item-id.outputs.project-item-id }}
field-keys: Trending
field-values: ${{ needs.extract-trend.outputs.trend_id }}