-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (78 loc) · 3.11 KB
/
prepopulate-issues.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
name: Populate Issues
on:
create:
# Allows this workflow to be manually run from the Actions tab
workflow_dispatch:
env:
ISSUES_DIR: ".github/STARTING_ISSUES/"
jobs:
create:
name: Create project and issues
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/feedback' }} # only run when feedback branch is created
# feedback branch is created just after repository creation
steps:
- uses: actions/checkout@v2
# create project and column to hold issue cards
# returns column ID of created column
- name: Create project and column
id: create-project
uses: actions/github-script@v4
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const responseProject = await github.projects.createForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'Assignment Tasks',
body: 'Complete the tasks outlined in each issue.',
});
console.log(`Create project response - status: ${responseProject.status}`)
const responseColumn = await github.projects.createColumn({
project_id: responseProject.data.id,
name: 'To Do',
});
console.log(`Create column response - status: ${responseColumn.status}`)
return responseColumn.data.id;
result-encoding: string
# read files from issue dir and create issue per file
- name: Create issues
id: create-issues
uses: actions/github-script@v4
env:
COLUMN_ID: ${{ steps.create-project.outputs.result }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const columnID = parseInt(process.env.COLUMN_ID);
const issuesDir = process.env.ISSUES_DIR;
const fs = require('fs');
const path = require('path');
try {
const files = fs.readdirSync(issuesDir);
for (const file of files) {
console.log(`File found: ${file}`);
console.log("Creating issue...");
// read file
let issueTitle = path.parse(file).name;
let issueBody = fs.readFileSync(path.join(issuesDir, file), "utf8");
// create issue
const responseIssue = await github.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: issueTitle,
body: issueBody,
});
console.log(`Create issue ${issueTitle} response - status: ${responseIssue.status}`);
// add issue to project board
github.projects.createCard({
column_id: columnID,
note: null,
content_id: responseIssue.data.id,
content_type: "Issue",
});
}
} catch (err) {
console.log(err);
core.setFailed(err.message);
}