autoforce 0.1.18 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.autoforce.json +1 -1
- package/CHANGELOG.md +10 -0
- package/lib/auto.js +47 -61
- package/lib/helpers/class.d.ts +1 -0
- package/lib/helpers/class.js +65 -78
- package/lib/helpers/connect.js +199 -213
- package/lib/helpers/context.d.ts +1 -1
- package/lib/helpers/context.js +275 -220
- package/lib/helpers/github-graphql.js +90 -113
- package/lib/helpers/github-project-graphql.js +100 -132
- package/lib/helpers/gitlab-graphql.js +68 -104
- package/lib/helpers/lwc.js +33 -46
- package/lib/helpers/object.js +38 -53
- package/lib/helpers/openai.js +10 -22
- package/lib/helpers/taskFunctions.js +328 -384
- package/lib/helpers/tasks.d.ts +1 -1
- package/lib/helpers/tasks.js +99 -119
- package/lib/helpers/template.js +4 -0
- package/lib/helpers/util.d.ts +0 -1
- package/lib/helpers/util.js +106 -163
- package/package.json +15 -10
@@ -1,26 +1,22 @@
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
-
});
|
9
|
-
};
|
10
1
|
import { graphql } from "@octokit/graphql";
|
11
2
|
import { Octokit } from "octokit";
|
12
3
|
export class GitHubApi {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
4
|
+
repoVar;
|
5
|
+
projectNumber;
|
6
|
+
graphqlAuth;
|
7
|
+
octokit;
|
8
|
+
_repository;
|
9
|
+
_labels;
|
10
|
+
_milestones;
|
11
|
+
_defaultColors = { 'red': 'b60205', 'orange': 'd93f0b', 'yellow': 'fbca04', 'green': '0e8a16', 'dupont': '006b75', 'light-blue': '1d76db', 'blue': '0052cc', 'purple': '5319e7', 'pastel-red': 'e99695', 'pastel-orange': 'f9d0c4', 'pastel-yellow': 'fef2c0', 'pastel-green': 'c2e0c6', 'pastel-dupont': 'bfdadc', 'pastel-light': 'c5def5', 'pastel-blue': 'bfd4f2', 'pastel-purple': 'd4c5f9' };
|
12
|
+
async getRepository() {
|
13
|
+
if (this._repository === undefined) {
|
14
|
+
const repository = await this.getRepositoryObject();
|
15
|
+
this._repository = repository;
|
16
|
+
}
|
17
|
+
return this._repository;
|
21
18
|
}
|
22
19
|
constructor(token, owner, repo, projectNumber) {
|
23
|
-
this._defaultColors = { 'red': 'b60205', 'orange': 'd93f0b', 'yellow': 'fbca04', 'green': '0e8a16', 'dupont': '006b75', 'light-blue': '1d76db', 'blue': '0052cc', 'purple': '5319e7', 'pastel-red': 'e99695', 'pastel-orange': 'f9d0c4', 'pastel-yellow': 'fef2c0', 'pastel-green': 'c2e0c6', 'pastel-dupont': 'bfdadc', 'pastel-light': 'c5def5', 'pastel-blue': 'bfd4f2', 'pastel-purple': 'd4c5f9' };
|
24
20
|
this.repoVar = { owner, repo };
|
25
21
|
this.projectNumber = projectNumber;
|
26
22
|
this.graphqlAuth = graphql.defaults({
|
@@ -33,17 +29,16 @@ export class GitHubApi {
|
|
33
29
|
auth: token
|
34
30
|
});
|
35
31
|
}
|
36
|
-
createLabel(
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
const mutationCreateLabel = `
|
32
|
+
async createLabel(name, color = 'random') {
|
33
|
+
const repositoryId = (await this.getRepository()).id;
|
34
|
+
if (color === 'random') {
|
35
|
+
color = this.getRandomColor();
|
36
|
+
}
|
37
|
+
else if (this._defaultColors[color] !== undefined) {
|
38
|
+
color = this._defaultColors[color];
|
39
|
+
}
|
40
|
+
const variables = { name, repositoryId, color };
|
41
|
+
const mutationCreateLabel = `
|
47
42
|
mutation createLabel( $name: String!, $repositoryId: ID!, $color: String! ) {
|
48
43
|
createLabel(
|
49
44
|
input: {
|
@@ -59,52 +54,46 @@ export class GitHubApi {
|
|
59
54
|
}
|
60
55
|
}
|
61
56
|
}`;
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
});
|
57
|
+
try {
|
58
|
+
const { createLabel } = await this.graphqlAuth(mutationCreateLabel, variables);
|
59
|
+
return createLabel.label;
|
60
|
+
}
|
61
|
+
catch (error) {
|
62
|
+
console.log(error);
|
63
|
+
}
|
64
|
+
return;
|
71
65
|
}
|
72
66
|
getRandomColor() {
|
73
67
|
const colors = Object.values(this._defaultColors);
|
74
68
|
const number = Math.floor(Math.random() * colors.length);
|
75
69
|
return colors[number];
|
76
70
|
}
|
77
|
-
createMilestone(
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
}
|
87
|
-
});
|
88
|
-
const milestone = { id: result.data.node_id, title: result.data.title, description: result.data.description, dueOn: result.data.due_on, url: result.data.url };
|
89
|
-
return milestone;
|
71
|
+
async createMilestone(title, state = 'open', description, dueOn) {
|
72
|
+
const result = await this.octokit.request(`POST /repos/${this.repoVar.owner}/${this.repoVar.repo}/milestones`, {
|
73
|
+
title,
|
74
|
+
state,
|
75
|
+
description,
|
76
|
+
due_on: dueOn,
|
77
|
+
headers: {
|
78
|
+
'X-GitHub-Api-Version': '2022-11-28'
|
79
|
+
}
|
90
80
|
});
|
81
|
+
const milestone = { id: result.data.node_id, title: result.data.title, description: result.data.description, dueOn: result.data.due_on, url: result.data.url };
|
82
|
+
return milestone;
|
91
83
|
}
|
92
|
-
getUser() {
|
93
|
-
|
94
|
-
const query = `{
|
84
|
+
async getUser() {
|
85
|
+
const query = `{
|
95
86
|
viewer {
|
96
87
|
login
|
97
88
|
id
|
98
89
|
}
|
99
90
|
}`;
|
100
|
-
|
101
|
-
|
102
|
-
});
|
91
|
+
const { viewer } = await this.graphqlAuth(query);
|
92
|
+
return viewer;
|
103
93
|
}
|
104
|
-
getLabels() {
|
105
|
-
|
106
|
-
|
107
|
-
const query = `
|
94
|
+
async getLabels() {
|
95
|
+
if (this._labels === undefined) {
|
96
|
+
const query = `
|
108
97
|
query getRepo($owner:String!, $repo: String! ) {
|
109
98
|
repository(owner: $owner, name: $repo) {
|
110
99
|
labels(last: 10, orderBy: { field: CREATED_AT, direction: DESC}) {
|
@@ -117,16 +106,14 @@ export class GitHubApi {
|
|
117
106
|
}
|
118
107
|
}
|
119
108
|
`;
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
});
|
109
|
+
const { repository } = await this.graphqlAuth(query, this.repoVar);
|
110
|
+
this._labels = repository.labels.nodes;
|
111
|
+
}
|
112
|
+
return this._labels;
|
125
113
|
}
|
126
|
-
getMilestones() {
|
127
|
-
|
128
|
-
|
129
|
-
const query = `
|
114
|
+
async getMilestones() {
|
115
|
+
if (this._milestones === undefined) {
|
116
|
+
const query = `
|
130
117
|
query getRepo($owner:String!, $repo: String! ) {
|
131
118
|
repository(owner: $owner, name: $repo) {
|
132
119
|
milestones(last: 10, states: OPEN, orderBy: { field: CREATED_AT, direction: DESC} ) {
|
@@ -140,15 +127,13 @@ export class GitHubApi {
|
|
140
127
|
}
|
141
128
|
}
|
142
129
|
`;
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
});
|
130
|
+
const { repository } = await this.graphqlAuth(query, this.repoVar);
|
131
|
+
this._milestones = repository.milestones.nodes;
|
132
|
+
}
|
133
|
+
return this._milestones;
|
148
134
|
}
|
149
|
-
getRepositoryObject() {
|
150
|
-
|
151
|
-
const query = `
|
135
|
+
async getRepositoryObject() {
|
136
|
+
const query = `
|
152
137
|
query getRepo($owner:String!, $repo: String!, $projectNumber: Int! ) {
|
153
138
|
repository(owner: $owner, name: $repo) {
|
154
139
|
id
|
@@ -168,16 +153,14 @@ export class GitHubApi {
|
|
168
153
|
}
|
169
154
|
}
|
170
155
|
`;
|
171
|
-
|
172
|
-
|
173
|
-
});
|
156
|
+
const { repository } = await this.graphqlAuth(query, { projectNumber: this.projectNumber, ...this.repoVar });
|
157
|
+
return repository;
|
174
158
|
}
|
175
|
-
createPullRequest(branchName, title, body) {
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
const mutationPullRequest = `
|
159
|
+
async createPullRequest(branchName, title, body) {
|
160
|
+
const repositoryId = (await this.getRepository()).id;
|
161
|
+
const headRefName = 'main';
|
162
|
+
const baseRefName = branchName;
|
163
|
+
const mutationPullRequest = `
|
181
164
|
mutation createPullRequest( $baseRefName: String!, $headRefName: String!, $headRepositoryId: ID, $repositoryId: ID!, $title: String!, $body: String ) {
|
182
165
|
createPullRequest(
|
183
166
|
input: {
|
@@ -194,20 +177,17 @@ export class GitHubApi {
|
|
194
177
|
}
|
195
178
|
}
|
196
179
|
}`;
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
});
|
180
|
+
try {
|
181
|
+
const { createPullRequest } = await this.graphqlAuth(mutationPullRequest, { baseRefName, headRefName, headRepositoryId: repositoryId, repositoryId, title, body });
|
182
|
+
return createPullRequest.pullRequest ? true : false;
|
183
|
+
}
|
184
|
+
catch (error) {
|
185
|
+
console.log(error);
|
186
|
+
}
|
187
|
+
return false;
|
206
188
|
}
|
207
|
-
assignBranchToIssue(issueNumber, branchName, commitSha) {
|
208
|
-
|
209
|
-
var _a;
|
210
|
-
const query = `
|
189
|
+
async assignBranchToIssue(issueNumber, branchName, commitSha) {
|
190
|
+
const query = `
|
211
191
|
query getIssue($owner:String!, $repo: String!, $issueNumber: Int!) {
|
212
192
|
repository(owner: $owner, name: $repo) {
|
213
193
|
issue(number: $issueNumber) {
|
@@ -216,10 +196,10 @@ export class GitHubApi {
|
|
216
196
|
}
|
217
197
|
}
|
218
198
|
`;
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
199
|
+
const { repository } = await this.graphqlAuth(query, { issueNumber: Number.parseInt(issueNumber), ...this.repoVar });
|
200
|
+
const issue = repository.issue;
|
201
|
+
const commit = await this.getCommit(commitSha);
|
202
|
+
const mutation = `
|
223
203
|
mutation createLinkedBranch( $issueId: ID!, $oid: GitObjectID!, $branchName: String!) {
|
224
204
|
createLinkedBranch(input: {
|
225
205
|
issueId: $issueId
|
@@ -232,13 +212,11 @@ export class GitHubApi {
|
|
232
212
|
}
|
233
213
|
}
|
234
214
|
}`;
|
235
|
-
|
236
|
-
|
237
|
-
});
|
215
|
+
const { createLinkedBranch } = await this.graphqlAuth(mutation, { issueId: issue.id, oid: commit.oid, branchName });
|
216
|
+
return createLinkedBranch?.issue?.id ? true : false;
|
238
217
|
}
|
239
|
-
getCommit(commitSha) {
|
240
|
-
|
241
|
-
const query = `
|
218
|
+
async getCommit(commitSha) {
|
219
|
+
const query = `
|
242
220
|
query getCommit($owner:String!, $repo: String!, $commitSha: String!) {
|
243
221
|
repository(owner: $owner, name: $repo) {
|
244
222
|
object(expression: $commitSha) {
|
@@ -249,8 +227,7 @@ export class GitHubApi {
|
|
249
227
|
}
|
250
228
|
}
|
251
229
|
} `;
|
252
|
-
|
253
|
-
|
254
|
-
});
|
230
|
+
const { repository } = await this.graphqlAuth(query, { commitSha, ...this.repoVar });
|
231
|
+
return repository.object;
|
255
232
|
}
|
256
233
|
}
|
@@ -1,22 +1,13 @@
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
-
});
|
9
|
-
};
|
10
1
|
import { logWarning } from "./color.js";
|
11
2
|
import { GitHubApi } from "./github-graphql.js";
|
12
3
|
export class GitHubProjectApi extends GitHubApi {
|
4
|
+
projectNumber;
|
13
5
|
constructor(token, owner, repo, projectNumber) {
|
14
6
|
super(token, owner, repo);
|
15
7
|
this.projectNumber = projectNumber;
|
16
8
|
}
|
17
|
-
getColumnValueMap() {
|
18
|
-
|
19
|
-
const query = `
|
9
|
+
async getColumnValueMap() {
|
10
|
+
const query = `
|
20
11
|
query getFieldOptions($owner:String!, $repo: String!, $projectNumber: Int!) {
|
21
12
|
repository(owner: $owner, name: $repo) {
|
22
13
|
projectV2(number: $projectNumber) {
|
@@ -34,55 +25,48 @@ export class GitHubProjectApi extends GitHubApi {
|
|
34
25
|
}
|
35
26
|
}
|
36
27
|
`;
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
});
|
28
|
+
const { repository } = await this.graphqlAuth(query, { projectNumber: this.projectNumber, ...this.repoVar });
|
29
|
+
const mapValues = {};
|
30
|
+
for (const option of repository.projectV2.field.options) {
|
31
|
+
mapValues[option.name] = option.id;
|
32
|
+
}
|
33
|
+
return mapValues;
|
44
34
|
}
|
45
|
-
findMilestoneByName(title) {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
return milestone;
|
53
|
-
}
|
35
|
+
async findMilestoneByName(title) {
|
36
|
+
if (title) {
|
37
|
+
const milestones = await this.getMilestones();
|
38
|
+
if (milestones.length > 0) {
|
39
|
+
for (const milestone of milestones) {
|
40
|
+
if (milestone.title === title) {
|
41
|
+
return milestone;
|
54
42
|
}
|
55
43
|
}
|
56
44
|
}
|
57
|
-
|
58
|
-
|
45
|
+
}
|
46
|
+
return;
|
59
47
|
}
|
60
|
-
findLabelByName(name) {
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
return label;
|
68
|
-
}
|
48
|
+
async findLabelByName(name) {
|
49
|
+
if (name) {
|
50
|
+
const labels = await this.getLabels();
|
51
|
+
if (labels.length > 0) {
|
52
|
+
for (const label of labels) {
|
53
|
+
if (label.name === name) {
|
54
|
+
return label;
|
69
55
|
}
|
70
56
|
}
|
71
57
|
}
|
72
|
-
|
73
|
-
|
58
|
+
}
|
59
|
+
return;
|
74
60
|
}
|
75
|
-
createIssue(title, state, label, body, milestone) {
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
const variables = { labelId, body, assignId: user.id, projectId, repositoryId, title, milestoneId: milestoneId ? milestoneId : null };
|
85
|
-
const mutationIssue = `
|
61
|
+
async createIssue(title, state, label, body, milestone) {
|
62
|
+
const user = await this.getUser();
|
63
|
+
const repository = await this.getRepository();
|
64
|
+
const repositoryId = repository.id;
|
65
|
+
const labelId = label?.startsWith('LA_') ? label : (await this.findLabelByName(label))?.id;
|
66
|
+
const milestoneId = milestone?.startsWith('MI_') ? milestone : (await this.findMilestoneByName(milestone))?.id;
|
67
|
+
const projectId = repository.projectV2.id;
|
68
|
+
const variables = { labelId, body, assignId: user.id, projectId, repositoryId, title, milestoneId: milestoneId ? milestoneId : null };
|
69
|
+
const mutationIssue = `
|
86
70
|
mutation createIssue($repositoryId: ID!, $assignId: ID!, $title: String!, $body: String, $milestoneId: ID ${labelId ? ', $labelId: ID!' : ''} ) {
|
87
71
|
createIssue(
|
88
72
|
input: {
|
@@ -106,12 +90,12 @@ export class GitHubProjectApi extends GitHubApi {
|
|
106
90
|
}
|
107
91
|
}
|
108
92
|
}`;
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
93
|
+
const { createIssue } = await this.graphqlAuth(mutationIssue, variables);
|
94
|
+
const issue = createIssue.issue;
|
95
|
+
if (!state || !issue.number) {
|
96
|
+
return issue;
|
97
|
+
}
|
98
|
+
const mutationItem = `
|
115
99
|
mutation addProjectV2ItemById($projectId: ID!, $contentId: ID! ) {
|
116
100
|
addProjectV2ItemById(
|
117
101
|
input: {
|
@@ -125,16 +109,16 @@ export class GitHubProjectApi extends GitHubApi {
|
|
125
109
|
}
|
126
110
|
}
|
127
111
|
}`;
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
112
|
+
const { addProjectV2ItemById } = await this.graphqlAuth(mutationItem, { projectId, contentId: issue.id });
|
113
|
+
const itemId = addProjectV2ItemById.item.id;
|
114
|
+
const fieldId = repository.projectV2.field.id;
|
115
|
+
const mapValues = await this.getColumnValueMap();
|
116
|
+
const columnValue = mapValues[state];
|
117
|
+
if (!columnValue) {
|
118
|
+
logWarning(`No se encontro la columna ${state} en las lista de columnas del proyecto ${Object.keys(mapValues).join(",")}`);
|
119
|
+
}
|
120
|
+
else {
|
121
|
+
const mutationColumn = `
|
138
122
|
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $columnValue: String!) {
|
139
123
|
updateProjectV2ItemFieldValue(
|
140
124
|
input: {
|
@@ -147,24 +131,19 @@ export class GitHubProjectApi extends GitHubApi {
|
|
147
131
|
clientMutationId
|
148
132
|
}
|
149
133
|
}`;
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
});
|
134
|
+
await this.graphqlAuth(mutationColumn, { projectId, itemId, fieldId, columnValue });
|
135
|
+
}
|
136
|
+
return issue;
|
154
137
|
}
|
155
|
-
getIssueState(issueNumber) {
|
156
|
-
|
157
|
-
|
158
|
-
const issue = yield this._getIssue(issueNumber);
|
159
|
-
return (_c = (_b = (_a = issue.projectItems) === null || _a === void 0 ? void 0 : _a.nodes[0]) === null || _b === void 0 ? void 0 : _b.fieldValueByName) === null || _c === void 0 ? void 0 : _c.name;
|
160
|
-
});
|
138
|
+
async getIssueState(issueNumber) {
|
139
|
+
const issue = await this._getIssue(issueNumber);
|
140
|
+
return issue.projectItems?.nodes[0]?.fieldValueByName?.name;
|
161
141
|
}
|
162
142
|
getIssueName(title) {
|
163
143
|
return title.toLowerCase().replaceAll(' ', '-');
|
164
144
|
}
|
165
|
-
_getIssue(issueNumber) {
|
166
|
-
|
167
|
-
const query = `
|
145
|
+
async _getIssue(issueNumber) {
|
146
|
+
const query = `
|
168
147
|
query getIssue($owner:String!, $repo: String!, $issueNumber: Int!) {
|
169
148
|
repository(owner: $owner, name: $repo) {
|
170
149
|
issue(number: $issueNumber) {
|
@@ -210,38 +189,32 @@ export class GitHubProjectApi extends GitHubApi {
|
|
210
189
|
}
|
211
190
|
}
|
212
191
|
`;
|
213
|
-
|
214
|
-
|
215
|
-
});
|
192
|
+
const { repository } = await this.graphqlAuth(query, { issueNumber: Number.parseInt(issueNumber), ...this.repoVar });
|
193
|
+
return repository.issue;
|
216
194
|
}
|
217
|
-
getIssue(issueNumber) {
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
issueObject.labels.push(node.name);
|
232
|
-
}
|
195
|
+
async getIssue(issueNumber) {
|
196
|
+
const issue = await this._getIssue(issueNumber);
|
197
|
+
const issueObject = { number: issue.number, title: issue.title, id: issue.id, url: issue.url, body: issue.body };
|
198
|
+
issueObject.name = this.getIssueName(issue.title);
|
199
|
+
if (issue.linkedBranches.nodes.length > 0) {
|
200
|
+
issueObject.branch = issue.linkedBranches.nodes[0].ref.name;
|
201
|
+
}
|
202
|
+
if (issue.projectItems.nodes.length > 0) {
|
203
|
+
issueObject.state = issue.projectItems.nodes[0].fieldValueByName.name;
|
204
|
+
}
|
205
|
+
if (issue.labels.nodes.length > 0) {
|
206
|
+
issueObject.labels = [];
|
207
|
+
for (const node of issue.labels.nodes) {
|
208
|
+
issueObject.labels.push(node.name);
|
233
209
|
}
|
234
|
-
|
235
|
-
|
210
|
+
}
|
211
|
+
return issueObject;
|
236
212
|
}
|
237
|
-
getIssues() {
|
238
|
-
return
|
239
|
-
return yield this.getIssuesWithFilter(`{ states: OPEN }`);
|
240
|
-
});
|
213
|
+
async getIssues() {
|
214
|
+
return await this.getIssuesWithFilter(`{ states: OPEN }`);
|
241
215
|
}
|
242
|
-
getIssuesWithFilter(filterBy) {
|
243
|
-
|
244
|
-
const query = `
|
216
|
+
async getIssuesWithFilter(filterBy) {
|
217
|
+
const query = `
|
245
218
|
query getIssues($owner:String!, $repo: String!) {
|
246
219
|
repository(owner: $owner, name: $repo) {
|
247
220
|
issues(last: 10, filterBy: ${filterBy} ) {
|
@@ -272,19 +245,17 @@ export class GitHubProjectApi extends GitHubApi {
|
|
272
245
|
}
|
273
246
|
}
|
274
247
|
`;
|
275
|
-
|
276
|
-
|
277
|
-
});
|
248
|
+
const { repository } = await this.graphqlAuth(query, this.repoVar);
|
249
|
+
return repository.issues.nodes;
|
278
250
|
}
|
279
|
-
moveIssue(issueNumber, state) {
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
const mutation = `
|
251
|
+
async moveIssue(issueNumber, state) {
|
252
|
+
const issue = await this._getIssue(issueNumber);
|
253
|
+
const itemId = issue.projectItems.nodes[0].id;
|
254
|
+
const projectId = issue.projectItems.nodes[0].project.id;
|
255
|
+
const fieldId = issue.projectItems.nodes[0].fieldValueByName.field.id;
|
256
|
+
const mapValues = await this.getColumnValueMap();
|
257
|
+
const columnValue = mapValues[state];
|
258
|
+
const mutation = `
|
288
259
|
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $columnValue: String!) {
|
289
260
|
updateProjectV2ItemFieldValue(
|
290
261
|
input: {
|
@@ -299,15 +270,13 @@ export class GitHubProjectApi extends GitHubApi {
|
|
299
270
|
}
|
300
271
|
}
|
301
272
|
}`;
|
302
|
-
|
303
|
-
|
304
|
-
});
|
273
|
+
const { updateProjectV2ItemFieldValue } = await this.graphqlAuth(mutation, { projectId, itemId, fieldId, columnValue });
|
274
|
+
return updateProjectV2ItemFieldValue?.projectV2Item ? true : false;
|
305
275
|
}
|
306
|
-
assignIssueToMe(issueNumber) {
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
const mutation = `
|
276
|
+
async assignIssueToMe(issueNumber) {
|
277
|
+
const user = await this.getUser();
|
278
|
+
const issue = await this._getIssue(issueNumber);
|
279
|
+
const mutation = `
|
311
280
|
mutation assignUser( $issueId: ID!, $userId: ID!) {
|
312
281
|
addAssigneesToAssignable(input: {
|
313
282
|
assignableId: $issueId
|
@@ -321,8 +290,7 @@ export class GitHubProjectApi extends GitHubApi {
|
|
321
290
|
}
|
322
291
|
}
|
323
292
|
`;
|
324
|
-
|
325
|
-
|
326
|
-
});
|
293
|
+
const { addAssigneesToAssignable } = await this.graphqlAuth(mutation, { issueId: issue.id, userId: user.id });
|
294
|
+
return addAssigneesToAssignable.assignable.assignees.totalCount > 0;
|
327
295
|
}
|
328
296
|
}
|