1+ name : 05-1. Use GitHub APIs
2+ on :
3+ workflow_dispatch :
4+ push :
5+
6+ # Limit the permissions of the GITHUB_TOKEN
7+ permissions :
8+ contents : read
9+ issues : write
10+
11+ jobs :
12+
13+ rest-api-create-and-close-issue :
14+ runs-on : ubuntu-latest
15+ steps :
16+ - uses : actions/github-script@v6
17+ id : create-issue
18+ with :
19+ github-token : ${{secrets.GITHUB_TOKEN}}
20+ script : |
21+ const result = await github.rest.issues.create({
22+ owner: context.repo.owner,
23+ repo: context.repo.repo,
24+ title: 'Issue auto-created from workflow run ${{github.run_id}}',
25+ body: '👋 Thank you! We appreciate your contribution to this project.',
26+ labels: ["training"]
27+ })
28+ console.log(result)
29+ return result.data
30+
31+ - name : Displays create issue result
32+ run : echo "${{toJSON(steps.create-issue.outputs.result)}}"
33+
34+ # Add here the close-issue step
35+
36+
37+ graphql-api-query-issues :
38+ needs : rest-api-create-and-close-issue
39+ runs-on : ubuntu-latest
40+ steps :
41+ - uses : actions/github-script@v6
42+ id : issues-result
43+ with :
44+ script : |
45+ const query = `query($owner:String!, $name:String!, $label:String!) {
46+ repository(owner:$owner, name:$name){
47+ issues(first:100, labels: [$label]) {
48+ nodes {
49+ number,
50+ title
51+ }
52+ }
53+ }
54+ }`;
55+ const variables = {
56+ owner: context.repo.owner,
57+ name: context.repo.repo,
58+ label: 'training'
59+ }
60+ const result = await github.graphql(query, variables)
61+ console.log(result.repository.issues.nodes)
62+ return result
63+
64+ - name : Displays training issues
65+ run : echo "${{toJSON(steps.issues-result.outputs.result)}}"
66+
67+
68+ # Add here the labels query step
69+
70+
71+
0 commit comments