autoforce 0.1.15 → 0.1.16
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 +16 -1
- package/lib/auto.js +4 -1
- package/lib/helpers/context.js +2 -2
- package/lib/helpers/github-graphql.d.ts +21 -17
- package/lib/helpers/github-graphql.js +89 -21
- package/lib/helpers/github-project-graphql.d.ts +1 -0
- package/lib/helpers/github-project-graphql.js +19 -3
- package/lib/helpers/gitlab-graphql.d.ts +11 -0
- package/lib/helpers/gitlab-graphql.js +12 -0
- package/lib/helpers/taskFunctions.js +35 -2
- package/lib/helpers/util.js +4 -1
- package/package.json +1 -1
package/.autoforce.json
CHANGED
package/CHANGELOG.md
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
# Versiones
|
2
|
+
|
3
|
+
## Version 0.1.15
|
4
|
+
- Fecha: 9 Dic 2024
|
5
|
+
- Paquete: [Descargar](https://www.npmjs.com/package/autoforce/v/0.1.15)
|
6
|
+
- Cambios:
|
7
|
+
* [new] que muestre la url
|
8
|
+
- https://github.com/sebastianclaros/autoforce/issues/37
|
9
|
+
* [list] falta templates en modelA
|
10
|
+
- https://github.com/sebastianclaros/autoforce/issues/38
|
11
|
+
|
12
|
+
## Version 0.1.13 y 0.1.14
|
13
|
+
- Fecha: 9 Dic 2024
|
14
|
+
- Cambios:
|
15
|
+
* Error en el publish por una dependencia erronea a si mismo
|
16
|
+
|
2
17
|
## Version 0.1.12
|
3
|
-
- Fecha: 8
|
18
|
+
- Fecha: 8 Dic 2024
|
4
19
|
- Paquete: [Descargar](https://www.npmjs.com/package/autoforce/v/0.1.12)
|
5
20
|
- Cambios:
|
6
21
|
* [Publish] ponga en Changelog todos los issues Closed del milestone asociado. Y los mueva al final de todo a la Columna "Published"
|
package/lib/auto.js
CHANGED
@@ -13,6 +13,8 @@ import { logError } from "./helpers/color.js";
|
|
13
13
|
import prompts from "prompts";
|
14
14
|
import { createConfigurationFile, getConfigFile } from "./helpers/util.js";
|
15
15
|
import context from "./helpers/context.js";
|
16
|
+
import { fileURLToPath } from "url";
|
17
|
+
import { dirname } from 'path';
|
16
18
|
const proxyCommand = {
|
17
19
|
'version': showVersion,
|
18
20
|
'config': createConfigurationFile
|
@@ -25,7 +27,8 @@ const taskCommand = {
|
|
25
27
|
};
|
26
28
|
function showVersion() {
|
27
29
|
return __awaiter(this, void 0, void 0, function* () {
|
28
|
-
const
|
30
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
31
|
+
const version = getConfigFile(__dirname + '/../.autoforce.json', 'version', '0.1.14');
|
29
32
|
console.log('AutoForce v' + version);
|
30
33
|
return true;
|
31
34
|
});
|
package/lib/helpers/context.js
CHANGED
@@ -63,7 +63,7 @@ class Context {
|
|
63
63
|
labels() {
|
64
64
|
return __awaiter(this, void 0, void 0, function* () {
|
65
65
|
var _a;
|
66
|
-
const choices = [{ value: '', title: 'Ninguno' }];
|
66
|
+
const choices = [{ value: '', title: 'Ninguno' }, { value: 'new', title: 'Nuevo' }];
|
67
67
|
const labels = yield ((_a = this.gitApi) === null || _a === void 0 ? void 0 : _a.getLabels());
|
68
68
|
if (labels) {
|
69
69
|
labels.forEach(label => choices.push({ value: label.name, title: label.name }));
|
@@ -89,7 +89,7 @@ class Context {
|
|
89
89
|
milestones() {
|
90
90
|
return __awaiter(this, void 0, void 0, function* () {
|
91
91
|
var _a;
|
92
|
-
const choices = [{ value: '', title: 'Ninguno' }];
|
92
|
+
const choices = [{ value: '', title: 'Ninguno' }, { value: 'new', title: 'Nuevo' }];
|
93
93
|
const milestones = yield ((_a = this.gitApi) === null || _a === void 0 ? void 0 : _a.getMilestones());
|
94
94
|
if (milestones) {
|
95
95
|
milestones.forEach(milestone => choices.push({ value: milestone.id, title: milestone.title }));
|
@@ -5,30 +5,34 @@ export declare class GitHubApi implements IGitApi {
|
|
5
5
|
};
|
6
6
|
projectNumber: number | undefined;
|
7
7
|
graphqlAuth: import("@octokit/graphql/types").graphql;
|
8
|
+
octokit: import("@octokit/core").Octokit & {
|
9
|
+
paginate: import("@octokit/plugin-paginate-rest").PaginateInterface;
|
10
|
+
} & import("@octokit/plugin-paginate-graphql").paginateGraphQLInterface & import("@octokit/plugin-rest-endpoint-methods").Api & {
|
11
|
+
retry: {
|
12
|
+
retryRequest: (error: import("octokit").RequestError, retries: number, retryAfter: number) => import("octokit").RequestError;
|
13
|
+
};
|
14
|
+
};
|
15
|
+
_repository: IRepository | undefined;
|
16
|
+
_labels: ILabel[] | undefined;
|
17
|
+
_defaultColors: Record<string, string>;
|
18
|
+
getRepository(): Promise<IRepository>;
|
8
19
|
constructor(token: string, owner: string, repo: string, projectNumber?: number);
|
20
|
+
createLabel(name: string, color?: string): Promise<ILabel | undefined>;
|
21
|
+
getRandomColor(): string;
|
22
|
+
createMilestone(title: string, state?: string, description?: string, dueOn?: string): Promise<{
|
23
|
+
id: any;
|
24
|
+
title: any;
|
25
|
+
description: any;
|
26
|
+
dueOn: any;
|
27
|
+
url: any;
|
28
|
+
}>;
|
9
29
|
getUser(): Promise<{
|
10
30
|
login: string;
|
11
31
|
id: number;
|
12
32
|
}>;
|
13
33
|
getLabels(): Promise<ILabel[]>;
|
14
34
|
getMilestones(): Promise<IMilestone[]>;
|
15
|
-
|
16
|
-
id: string;
|
17
|
-
label?: {
|
18
|
-
id: string;
|
19
|
-
};
|
20
|
-
projectV2: {
|
21
|
-
id: string;
|
22
|
-
field: {
|
23
|
-
id: string;
|
24
|
-
name: string;
|
25
|
-
options: {
|
26
|
-
name: string;
|
27
|
-
id: string;
|
28
|
-
}[];
|
29
|
-
};
|
30
|
-
};
|
31
|
-
}>;
|
35
|
+
getRepositoryObject(): Promise<IRepository>;
|
32
36
|
createPullRequest(branchName: string, title: string, body: string): Promise<boolean>;
|
33
37
|
assignBranchToIssue(issueNumber: string, branchName: string, commitSha: string): Promise<boolean>;
|
34
38
|
getCommit(commitSha: string): Promise<{
|
@@ -8,8 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
8
8
|
});
|
9
9
|
};
|
10
10
|
import { graphql } from "@octokit/graphql";
|
11
|
+
import { Octokit } from "octokit";
|
11
12
|
export class GitHubApi {
|
13
|
+
getRepository() {
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
15
|
+
if (this._repository === undefined) {
|
16
|
+
const repository = yield this.getRepositoryObject();
|
17
|
+
this._repository = repository;
|
18
|
+
}
|
19
|
+
return this._repository;
|
20
|
+
});
|
21
|
+
}
|
12
22
|
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' };
|
13
24
|
this.repoVar = { owner, repo };
|
14
25
|
this.projectNumber = projectNumber;
|
15
26
|
this.graphqlAuth = graphql.defaults({
|
@@ -18,6 +29,65 @@ export class GitHubApi {
|
|
18
29
|
"X-Github-Next-Global-ID": 1
|
19
30
|
},
|
20
31
|
});
|
32
|
+
this.octokit = new Octokit({
|
33
|
+
auth: token
|
34
|
+
});
|
35
|
+
}
|
36
|
+
createLabel(name_1) {
|
37
|
+
return __awaiter(this, arguments, void 0, function* (name, color = 'random') {
|
38
|
+
const repositoryId = (yield this.getRepository()).id;
|
39
|
+
if (color === 'random') {
|
40
|
+
color = this.getRandomColor();
|
41
|
+
}
|
42
|
+
else if (this._defaultColors[color] !== undefined) {
|
43
|
+
color = this._defaultColors[color];
|
44
|
+
}
|
45
|
+
const variables = { name, repositoryId, color };
|
46
|
+
const mutationCreateLabel = `
|
47
|
+
mutation createLabel( $name: String!, $repositoryId: ID!, $color: String! ) {
|
48
|
+
createLabel(
|
49
|
+
input: {
|
50
|
+
repositoryId: $repositoryId,
|
51
|
+
name: $name
|
52
|
+
color: $color
|
53
|
+
}
|
54
|
+
) {
|
55
|
+
label {
|
56
|
+
id
|
57
|
+
name
|
58
|
+
color
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}`;
|
62
|
+
try {
|
63
|
+
const { createLabel } = yield this.graphqlAuth(mutationCreateLabel, variables);
|
64
|
+
return createLabel.label;
|
65
|
+
}
|
66
|
+
catch (error) {
|
67
|
+
console.log(error);
|
68
|
+
}
|
69
|
+
return;
|
70
|
+
});
|
71
|
+
}
|
72
|
+
getRandomColor() {
|
73
|
+
const colors = Object.values(this._defaultColors);
|
74
|
+
const number = Math.floor(Math.random() * colors.length);
|
75
|
+
return colors[number];
|
76
|
+
}
|
77
|
+
createMilestone(title_1) {
|
78
|
+
return __awaiter(this, arguments, void 0, function* (title, state = 'open', description, dueOn) {
|
79
|
+
const result = yield this.octokit.request(`POST /repos/${this.repoVar.owner}/${this.repoVar.repo}/milestones`, {
|
80
|
+
title,
|
81
|
+
state,
|
82
|
+
description,
|
83
|
+
due_on: dueOn,
|
84
|
+
headers: {
|
85
|
+
'X-GitHub-Api-Version': '2022-11-28'
|
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;
|
90
|
+
});
|
21
91
|
}
|
22
92
|
getUser() {
|
23
93
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -33,21 +103,24 @@ export class GitHubApi {
|
|
33
103
|
}
|
34
104
|
getLabels() {
|
35
105
|
return __awaiter(this, void 0, void 0, function* () {
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
106
|
+
if (this._labels === undefined) {
|
107
|
+
const query = `
|
108
|
+
query getRepo($owner:String!, $repo: String! ) {
|
109
|
+
repository(owner: $owner, name: $repo) {
|
110
|
+
labels(last: 10, orderBy: { field: CREATED_AT, direction: DESC}) {
|
111
|
+
nodes{
|
112
|
+
id
|
113
|
+
name
|
114
|
+
color
|
115
|
+
}
|
44
116
|
}
|
45
117
|
}
|
46
118
|
}
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
119
|
+
`;
|
120
|
+
const { repository } = yield this.graphqlAuth(query, this.repoVar);
|
121
|
+
this._labels = repository.labels.nodes;
|
122
|
+
}
|
123
|
+
return this._labels;
|
51
124
|
});
|
52
125
|
}
|
53
126
|
getMilestones() {
|
@@ -70,16 +143,12 @@ export class GitHubApi {
|
|
70
143
|
return repository.milestones.nodes;
|
71
144
|
});
|
72
145
|
}
|
73
|
-
|
146
|
+
getRepositoryObject() {
|
74
147
|
return __awaiter(this, void 0, void 0, function* () {
|
75
148
|
const query = `
|
76
|
-
query getRepo($owner:String!, $repo: String!, $projectNumber: Int
|
149
|
+
query getRepo($owner:String!, $repo: String!, $projectNumber: Int! ) {
|
77
150
|
repository(owner: $owner, name: $repo) {
|
78
151
|
id
|
79
|
-
${label ?
|
80
|
-
`label(name: $label) {
|
81
|
-
id
|
82
|
-
}` : ''}
|
83
152
|
projectV2( number: $projectNumber ) {
|
84
153
|
id
|
85
154
|
field(name: "Status") {
|
@@ -96,14 +165,13 @@ export class GitHubApi {
|
|
96
165
|
}
|
97
166
|
}
|
98
167
|
`;
|
99
|
-
const { repository } = yield this.graphqlAuth(query, Object.assign({
|
168
|
+
const { repository } = yield this.graphqlAuth(query, Object.assign({ projectNumber: this.projectNumber }, this.repoVar));
|
100
169
|
return repository;
|
101
170
|
});
|
102
171
|
}
|
103
172
|
createPullRequest(branchName, title, body) {
|
104
173
|
return __awaiter(this, void 0, void 0, function* () {
|
105
|
-
const
|
106
|
-
const repositoryId = repository.id;
|
174
|
+
const repositoryId = (yield this.getRepository()).id;
|
107
175
|
const headRefName = 'main';
|
108
176
|
const baseRefName = branchName;
|
109
177
|
const mutationPullRequest = `
|
@@ -3,6 +3,7 @@ export declare class GitHubProjectApi extends GitHubApi implements IProjectApi {
|
|
3
3
|
projectNumber: number;
|
4
4
|
constructor(token: string, owner: string, repo: string, projectNumber: number);
|
5
5
|
getColumnValueMap(): Promise<Record<string, string>>;
|
6
|
+
findLabelByName(name: string | undefined): Promise<ILabel | undefined>;
|
6
7
|
createIssue(title: string, state?: string, label?: string, body?: string, milestoneId?: string): Promise<IIssueObject>;
|
7
8
|
getIssueState(issueNumber: string): Promise<string>;
|
8
9
|
getIssueName(title: string): string;
|
@@ -42,14 +42,30 @@ export class GitHubProjectApi extends GitHubApi {
|
|
42
42
|
return mapValues;
|
43
43
|
});
|
44
44
|
}
|
45
|
+
findLabelByName(name) {
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
47
|
+
if (name) {
|
48
|
+
const labels = yield this.getLabels();
|
49
|
+
if (labels.length > 0) {
|
50
|
+
for (const label of labels) {
|
51
|
+
if (label.name === name) {
|
52
|
+
return label;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
return;
|
58
|
+
});
|
59
|
+
}
|
45
60
|
createIssue(title, state, label, body, milestoneId) {
|
46
61
|
return __awaiter(this, void 0, void 0, function* () {
|
47
62
|
var _a;
|
48
63
|
const user = yield this.getUser();
|
49
|
-
const repository = yield this.getRepository(
|
64
|
+
const repository = yield this.getRepository();
|
50
65
|
const repositoryId = repository.id;
|
51
|
-
const labelId = (_a =
|
66
|
+
const labelId = (label === null || label === void 0 ? void 0 : label.startsWith('LA_')) ? label : (_a = (yield this.findLabelByName(label))) === null || _a === void 0 ? void 0 : _a.id;
|
52
67
|
const projectId = repository.projectV2.id;
|
68
|
+
const variables = { labelId, body, assignId: user.id, projectId, repositoryId, title, milestoneId: milestoneId ? milestoneId : null };
|
53
69
|
const mutationIssue = `
|
54
70
|
mutation createIssue($repositoryId: ID!, $assignId: ID!, $title: String!, $body: String, $milestoneId: ID ${labelId ? ', $labelId: ID!' : ''} ) {
|
55
71
|
createIssue(
|
@@ -74,7 +90,7 @@ export class GitHubProjectApi extends GitHubApi {
|
|
74
90
|
}
|
75
91
|
}
|
76
92
|
}`;
|
77
|
-
const { createIssue } = yield this.graphqlAuth(mutationIssue,
|
93
|
+
const { createIssue } = yield this.graphqlAuth(mutationIssue, variables);
|
78
94
|
const issue = createIssue.issue;
|
79
95
|
if (!state || !issue.number) {
|
80
96
|
return issue;
|
@@ -13,6 +13,17 @@ export declare class GitLabApi implements IGitApi, IProjectApi {
|
|
13
13
|
getIssue(issueNumber: string): Promise<{}>;
|
14
14
|
getIssues(): Promise<never[]>;
|
15
15
|
getIssuesWithFilter(filter: string): Promise<never[]>;
|
16
|
+
createLabel(name: string, color?: string): Promise<{
|
17
|
+
id: string;
|
18
|
+
name: string;
|
19
|
+
color: string;
|
20
|
+
}>;
|
21
|
+
createMilestone(title: string, state?: string, description?: string, dueOn?: string): Promise<{
|
22
|
+
id: string;
|
23
|
+
title: string;
|
24
|
+
state: string;
|
25
|
+
url: string;
|
26
|
+
}>;
|
16
27
|
createIssue(title: string, state?: string, label?: string, body?: string, milestone?: string): Promise<{
|
17
28
|
number: number;
|
18
29
|
}>;
|
@@ -42,6 +42,18 @@ export class GitLabApi {
|
|
42
42
|
return [];
|
43
43
|
});
|
44
44
|
}
|
45
|
+
createLabel(name_1) {
|
46
|
+
return __awaiter(this, arguments, void 0, function* (name, color = 'random') {
|
47
|
+
console.log(name, color);
|
48
|
+
return { id: '', name, color };
|
49
|
+
});
|
50
|
+
}
|
51
|
+
createMilestone(title_1) {
|
52
|
+
return __awaiter(this, arguments, void 0, function* (title, state = 'open', description, dueOn) {
|
53
|
+
console.log(title, state, description, dueOn);
|
54
|
+
return { id: '', title: '', state: '', url: '' };
|
55
|
+
});
|
56
|
+
}
|
45
57
|
createIssue(title, state, label, body, milestone) {
|
46
58
|
return __awaiter(this, void 0, void 0, function* () {
|
47
59
|
console.log(title, state, label, body, milestone);
|
@@ -335,10 +335,43 @@ export const taskFunctions = {
|
|
335
335
|
},
|
336
336
|
createIssue(title, label, body, milestone) {
|
337
337
|
return __awaiter(this, void 0, void 0, function* () {
|
338
|
-
if (context.projectApi === undefined) {
|
338
|
+
if (context.projectApi === undefined || context.gitApi === undefined) {
|
339
339
|
return false;
|
340
340
|
}
|
341
|
-
|
341
|
+
if (label === 'new') {
|
342
|
+
const answer = yield prompts([
|
343
|
+
{
|
344
|
+
message: 'Nombre del Label',
|
345
|
+
name: 'nombre',
|
346
|
+
type: 'text'
|
347
|
+
}
|
348
|
+
]);
|
349
|
+
if (answer.nombre !== undefined) {
|
350
|
+
const result = yield context.gitApi.createLabel(answer.nombre);
|
351
|
+
if (result === null || result === void 0 ? void 0 : result.id) {
|
352
|
+
label = result.id;
|
353
|
+
}
|
354
|
+
}
|
355
|
+
else {
|
356
|
+
label = '';
|
357
|
+
}
|
358
|
+
}
|
359
|
+
if (milestone === 'new') {
|
360
|
+
const answer = yield prompts([
|
361
|
+
{
|
362
|
+
message: 'Nombre del Milestone',
|
363
|
+
name: 'nombre',
|
364
|
+
type: 'text'
|
365
|
+
}
|
366
|
+
]);
|
367
|
+
if (answer.nombre !== undefined) {
|
368
|
+
const result = yield context.gitApi.createMilestone(answer.nombre);
|
369
|
+
milestone = result === null || result === void 0 ? void 0 : result.id;
|
370
|
+
}
|
371
|
+
else {
|
372
|
+
milestone = '';
|
373
|
+
}
|
374
|
+
}
|
342
375
|
const issue = yield context.projectApi.createIssue(title, context.backlogColumn, label, body, milestone);
|
343
376
|
if (issue) {
|
344
377
|
console.log(`Se creo el issue ${issue.number}`);
|
package/lib/helpers/util.js
CHANGED
@@ -34,7 +34,10 @@ export function titlesToChoices(list, titleToValue = (title) => title) {
|
|
34
34
|
export function getDataFromPackage() {
|
35
35
|
const data = {};
|
36
36
|
try {
|
37
|
-
const filename =
|
37
|
+
const filename = searchInFolderHierarchy("package.json", process.cwd());
|
38
|
+
if (!filename) {
|
39
|
+
throw new Error("No se encontro el package.json en " + process.cwd());
|
40
|
+
}
|
38
41
|
const content = fs.readFileSync(filename, "utf8");
|
39
42
|
const packageJson = JSON.parse(content);
|
40
43
|
if (packageJson.repository) {
|