forked from monry/actions-add-issue-to-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
106 lines (103 loc) · 3.32 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
name: "Add Issue to Project"
author: 'Tetsuya Mori'
description: 'Add GitHub Issues to GitHub Projects (Beta)'
branding:
icon: plus-square
color: green
inputs:
github-token:
default: ''
required: true
description: 'Personal Access Token that with `repo`, `project`, `org:read` and `org:write` is granted.'
project-id:
default: ''
required: false
description: 'Node Id of project.'
project-owner:
default: ''
required: false
description: 'User/Organization name project contains.'
project-number:
default: 0
required: false
description: 'The number of the target project.'
issue-id:
default: ''
required: false
description: 'Node Id of issue.'
issue-repository:
default: ''
required: false
description: 'Repository name with owner of issue.'
issue-number:
default: 0
required: false
description: 'Number of issue.'
outputs:
added-project-item-id:
description: 'Project Item Id that added to project.'
value: ${{ steps.add-issue-to-project.outputs.added-project-item-id }}
error:
description: 'Error message.'
value: ${{ steps.add-issue-to-project.outputs.error }}
runs:
using: "composite"
steps:
- uses: monry/actions-get-project-id@v2
id: get-project-id
if: inputs.project-id == ''
with:
github-token: ${{ inputs.github-token }}
project-owner: ${{ inputs.project-owner }}
project-number: ${{ inputs.project-number }}
- uses: monry/actions-get-issue-id@v1
id: get-issue-id
if: inputs.issue-id == ''
with:
github-token: ${{ inputs.github-token }}
issue-repository: ${{ inputs.issue-repository }}
issue-number: ${{ inputs.issue-number }}
- name: Add Issue to Project
uses: actions/github-script@v6
id: add-issue-to-project
with:
result-encoding: string
github-token: ${{ inputs.github-token }}
script: |
var projectId = '${{ inputs.project-id }}' || '${{ steps.get-project-id.outputs.project-id }}';
if (!projectId) {
core.setOutput('error', 'Project does not found.');
return;
}
var issueId = '${{ inputs.issue-id }}' || '${{ steps.get-issue-id.outputs.issue-id }}';
if (!issueId) {
core.setOutput('error', 'Issue does not found.');
return;
}
const variables = {
projectId: projectId,
issueId: issueId
};
const mutation = `
mutation($projectId: ID!, $issueId: ID!) {
addProjectV2ItemById(input: {projectId: $projectId, contentId: $issueId}) {
item {
id
}
}
}
`;
let addedProjectV2ItemId = null;
try {
var result = await github.graphql(mutation, variables);
if (result && result.addProjectV2ItemById && result.addProjectV2ItemById.item) {
addedProjectV2ItemId = result.addProjectV2ItemById.item.id;
}
} catch (error) {
if (error.errors && error.errors.length > 0) {
core.setOutput('error', error.errors[0].message);
return;
}
}
core.setOutput('added-project-item-id', addedProjectV2ItemId);
return;