-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
115 lines (106 loc) · 3.58 KB
/
action.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
name: 'Grasp issue dependencies'
description: 'Help project managers and project owners with easy-to-understand views of github issue dependencies.'
inputs:
label:
description: 'Analyze the issue with the specified label'
required: true
github_token:
description: 'GitHub Access Token'
required: true
runs:
using: "composite"
steps:
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('~/.cargo/bin/gid') }}-0.2.1
- name: Install gid
shell: bash
run: |
cargo -vV
which gid || cargo install --version 0.2.1 gid_cli
- uses: actions/github-script@v6
env:
LABEL: '${{ inputs.label }}'
GITHUB_ACCESS_TOKEN: ${{ inputs.github_token }}
with:
script: |
const query = `
query ($owner: String!, $name: String!, $label: String!) {
repository(owner: $owner, name: $name) {
issues(first: 100, labels: [$label], states: OPEN) {
nodes {
number
}
}
}
}`;
const {LABEL} = process.env
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
label: LABEL
}
const result = await github.graphql(query, variables)
for (const issue of result.repository.issues.nodes) {
const query = `
query ($owner: String!, $name: String!, $number: Int!) {
repository(owner: $owner, name: $name) {
issue(number: $number) {
comments(first: 100) {
nodes {
databaseId
body
}
}
}
}
}`;
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
number: issue.number
}
const result = await github.graphql(query, variables)
let id = null;
for (const comment of result.repository.issue.comments.nodes) {
if(comment.body.includes("/generate_gid")) {
id = comment.databaseId
}
}
const { exec } = require("child_process");
const command = `gid -o ${context.repo.owner} -r ${context.repo.repo} -i ${issue.number}`
exec(command, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
const mermaid = `${stdout}`;
if (id === null) {
console.log("add new comment", mermaid);
github.rest.issues.createComment({
issue_number: issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `/generate_gid\n${mermaid}`
})
} else {
console.log("update comment", mermaid);
github.rest.issues.updateComment({
comment_id: id,
owner: context.repo.owner,
repo: context.repo.repo,
body: `/generate_gid\n${mermaid}`
})
}
});
}