autoforce 0.1.15 → 0.1.17

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.15",
2
+ "version": "0.1.17",
3
3
  "backlogColumn": "Todo",
4
4
  "model": "modelC",
5
5
  "modelTemplates": "modelB",
package/CHANGELOG.md CHANGED
@@ -1,6 +1,32 @@
1
1
  # Versiones
2
+
3
+ ## Version 0.1.16
4
+ - Fecha:
5
+ - Paquete: [Descargar](https://www.npmjs.com/package/autoforce/v/0.1.16)
6
+ - Cambios:
7
+ * [new] new milestone
8
+ - https://github.com/sebastianclaros/autoforce/issues/34
9
+ * Pincha en subdirectorios buscando el package.json
10
+ - https://github.com/sebastianclaros/autoforce/issues/39
11
+ * Comando new Label
12
+ - https://github.com/sebastianclaros/autoforce/issues/43
13
+
14
+ ## Version 0.1.15
15
+ - Fecha: 9 Dic 2024
16
+ - Paquete: [Descargar](https://www.npmjs.com/package/autoforce/v/0.1.15)
17
+ - Cambios:
18
+ * [new] que muestre la url
19
+ - https://github.com/sebastianclaros/autoforce/issues/37
20
+ * [list] falta templates en modelA
21
+ - https://github.com/sebastianclaros/autoforce/issues/38
22
+
23
+ ## Version 0.1.13 y 0.1.14
24
+ - Fecha: 9 Dic 2024
25
+ - Cambios:
26
+ * Error en el publish por una dependencia erronea a si mismo
27
+
2
28
  ## Version 0.1.12
3
- - Fecha: 8/12/2024
29
+ - Fecha: 8 Dic 2024
4
30
  - Paquete: [Descargar](https://www.npmjs.com/package/autoforce/v/0.1.12)
5
31
  - Cambios:
6
32
  * [Publish] ponga en Changelog todos los issues Closed del milestone asociado. Y los mueva al final de todo a la Columna "Published"
@@ -7,9 +7,9 @@
7
7
  {
8
8
  "name": "validate issue",
9
9
  "function": "validateIssue",
10
- "arguments": ["${newIssueNumber}", "Ready,Backlog"],
11
- "description": "Valida que Issue este en la Columna Ready o Backlog",
12
- "errorMessage": "Por favor verifique que el issue ${newIssueNumber} este en la columna Ready o Backlog"
10
+ "arguments": ["${newIssueNumber}", "Todo"],
11
+ "description": "Valida que Issue este en la Columna Todo",
12
+ "errorMessage": "Por favor verifique que el issue ${newIssueNumber} este en la columna Todo"
13
13
  },
14
14
  {
15
15
  "name": "check Issue type based on Labels",
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 version = getConfigFile('../.autoforce.json', 'version', '0.1.14');
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
  });
@@ -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,35 @@ 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
+ _milestones: IMilestone[] | undefined;
18
+ _defaultColors: Record<string, string>;
19
+ getRepository(): Promise<IRepository>;
8
20
  constructor(token: string, owner: string, repo: string, projectNumber?: number);
21
+ createLabel(name: string, color?: string): Promise<ILabel | undefined>;
22
+ getRandomColor(): string;
23
+ createMilestone(title: string, state?: string, description?: string, dueOn?: string): Promise<{
24
+ id: any;
25
+ title: any;
26
+ description: any;
27
+ dueOn: any;
28
+ url: any;
29
+ }>;
9
30
  getUser(): Promise<{
10
31
  login: string;
11
32
  id: number;
12
33
  }>;
13
34
  getLabels(): Promise<ILabel[]>;
14
35
  getMilestones(): Promise<IMilestone[]>;
15
- getRepository(label?: string): Promise<{
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
- }>;
36
+ getRepositoryObject(): Promise<IRepository>;
32
37
  createPullRequest(branchName: string, title: string, body: string): Promise<boolean>;
33
38
  assignBranchToIssue(issueNumber: string, branchName: string, commitSha: string): Promise<boolean>;
34
39
  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,26 +103,30 @@ export class GitHubApi {
33
103
  }
34
104
  getLabels() {
35
105
  return __awaiter(this, void 0, void 0, function* () {
36
- const query = `
37
- query getRepo($owner:String!, $repo: String! ) {
38
- repository(owner: $owner, name: $repo) {
39
- labels(last: 10, orderBy: { field: CREATED_AT, direction: DESC}) {
40
- nodes{
41
- id
42
- name
43
- color
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
- const { repository } = yield this.graphqlAuth(query, this.repoVar);
50
- return repository.labels.nodes;
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() {
54
127
  return __awaiter(this, void 0, void 0, function* () {
55
- const query = `
128
+ if (this._milestones === undefined) {
129
+ const query = `
56
130
  query getRepo($owner:String!, $repo: String! ) {
57
131
  repository(owner: $owner, name: $repo) {
58
132
  milestones(last: 10, states: OPEN, orderBy: { field: CREATED_AT, direction: DESC} ) {
@@ -66,20 +140,18 @@ export class GitHubApi {
66
140
  }
67
141
  }
68
142
  `;
69
- const { repository } = yield this.graphqlAuth(query, this.repoVar);
70
- return repository.milestones.nodes;
143
+ const { repository } = yield this.graphqlAuth(query, this.repoVar);
144
+ this._milestones = repository.milestones.nodes;
145
+ }
146
+ return this._milestones;
71
147
  });
72
148
  }
73
- getRepository(label) {
149
+ getRepositoryObject() {
74
150
  return __awaiter(this, void 0, void 0, function* () {
75
151
  const query = `
76
- query getRepo($owner:String!, $repo: String!, $projectNumber: Int!, ${label ? '$label: String!' : ''} ) {
152
+ query getRepo($owner:String!, $repo: String!, $projectNumber: Int! ) {
77
153
  repository(owner: $owner, name: $repo) {
78
154
  id
79
- ${label ?
80
- `label(name: $label) {
81
- id
82
- }` : ''}
83
155
  projectV2( number: $projectNumber ) {
84
156
  id
85
157
  field(name: "Status") {
@@ -96,14 +168,13 @@ export class GitHubApi {
96
168
  }
97
169
  }
98
170
  `;
99
- const { repository } = yield this.graphqlAuth(query, Object.assign({ label, projectNumber: this.projectNumber }, this.repoVar));
171
+ const { repository } = yield this.graphqlAuth(query, Object.assign({ projectNumber: this.projectNumber }, this.repoVar));
100
172
  return repository;
101
173
  });
102
174
  }
103
175
  createPullRequest(branchName, title, body) {
104
176
  return __awaiter(this, void 0, void 0, function* () {
105
- const repository = yield this.getRepository();
106
- const repositoryId = repository.id;
177
+ const repositoryId = (yield this.getRepository()).id;
107
178
  const headRefName = 'main';
108
179
  const baseRefName = branchName;
109
180
  const mutationPullRequest = `
@@ -3,7 +3,9 @@ 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
- createIssue(title: string, state?: string, label?: string, body?: string, milestoneId?: string): Promise<IIssueObject>;
6
+ findMilestoneByName(title: string | undefined): Promise<IMilestone | undefined>;
7
+ findLabelByName(name: string | undefined): Promise<ILabel | undefined>;
8
+ createIssue(title: string, state?: string, label?: string, body?: string, milestone?: string): Promise<IIssueObject>;
7
9
  getIssueState(issueNumber: string): Promise<string>;
8
10
  getIssueName(title: string): string;
9
11
  _getIssue(issueNumber: string): Promise<{
@@ -42,14 +42,46 @@ export class GitHubProjectApi extends GitHubApi {
42
42
  return mapValues;
43
43
  });
44
44
  }
45
- createIssue(title, state, label, body, milestoneId) {
45
+ findMilestoneByName(title) {
46
46
  return __awaiter(this, void 0, void 0, function* () {
47
- var _a;
47
+ if (title) {
48
+ const milestones = yield this.getMilestones();
49
+ if (milestones.length > 0) {
50
+ for (const milestone of milestones) {
51
+ if (milestone.title === title) {
52
+ return milestone;
53
+ }
54
+ }
55
+ }
56
+ }
57
+ return;
58
+ });
59
+ }
60
+ findLabelByName(name) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ if (name) {
63
+ const labels = yield this.getLabels();
64
+ if (labels.length > 0) {
65
+ for (const label of labels) {
66
+ if (label.name === name) {
67
+ return label;
68
+ }
69
+ }
70
+ }
71
+ }
72
+ return;
73
+ });
74
+ }
75
+ createIssue(title, state, label, body, milestone) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ var _a, _b;
48
78
  const user = yield this.getUser();
49
- const repository = yield this.getRepository(label);
79
+ const repository = yield this.getRepository();
50
80
  const repositoryId = repository.id;
51
- const labelId = (_a = repository.label) === null || _a === void 0 ? void 0 : _a.id;
81
+ 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;
82
+ const milestoneId = (milestone === null || milestone === void 0 ? void 0 : milestone.startsWith('MI_')) ? milestone : (_b = (yield this.findMilestoneByName(milestone))) === null || _b === void 0 ? void 0 : _b.id;
52
83
  const projectId = repository.projectV2.id;
84
+ const variables = { labelId, body, assignId: user.id, projectId, repositoryId, title, milestoneId: milestoneId ? milestoneId : null };
53
85
  const mutationIssue = `
54
86
  mutation createIssue($repositoryId: ID!, $assignId: ID!, $title: String!, $body: String, $milestoneId: ID ${labelId ? ', $labelId: ID!' : ''} ) {
55
87
  createIssue(
@@ -74,7 +106,7 @@ export class GitHubProjectApi extends GitHubApi {
74
106
  }
75
107
  }
76
108
  }`;
77
- const { createIssue } = yield this.graphqlAuth(mutationIssue, { labelId, body, assignId: user.id, projectId, repositoryId, title, milestoneId: milestoneId ? milestoneId : null, label: label ? [label] : null });
109
+ const { createIssue } = yield this.graphqlAuth(mutationIssue, variables);
78
110
  const issue = createIssue.issue;
79
111
  if (!state || !issue.number) {
80
112
  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
- console.log(milestone);
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}`);
@@ -373,7 +406,7 @@ export const taskFunctions = {
373
406
  },
374
407
  validaNoseaBranchActual(newBranchName) {
375
408
  return __awaiter(this, void 0, void 0, function* () {
376
- return this.getBranchName() !== newBranchName;
409
+ return getBranchName() !== newBranchName;
377
410
  });
378
411
  },
379
412
  checkCommitPending() {
@@ -394,7 +427,7 @@ export const taskFunctions = {
394
427
  try {
395
428
  const newBranchName = context.newBranchName;
396
429
  executeShell(`git checkout -b ${newBranchName} origin/main`);
397
- context.set('branchName', this.getBranchName());
430
+ context.set('branchName', getBranchName());
398
431
  return true;
399
432
  }
400
433
  catch (error) {
@@ -13,7 +13,7 @@ import prompts from "prompts";
13
13
  import context, { ProjectServices, GitServices } from "./context.js";
14
14
  import { logInfo, logWarning } from "./color.js";
15
15
  const COMMAND_FOLDER = searchInFolderHierarchy('commands', fileURLToPath(import.meta.url));
16
- export const CONFIG_FILE = process.cwd() + '/.autoforce.json';
16
+ export const CONFIG_FILE = searchInFolderHierarchy('.autoforce.json', fileURLToPath(import.meta.url));
17
17
  export const TEMPLATES_FOLDER = searchInFolderHierarchy('templates', fileURLToPath(import.meta.url));
18
18
  export const TEMPLATE_MODEL_FOLDER = TEMPLATES_FOLDER + '/' + getConfig('modelTemplates', 'modelA');
19
19
  export const DICTIONARY_FOLDER = TEMPLATE_MODEL_FOLDER + "/diccionarios";
@@ -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 = process.cwd() + "/package.json";
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) {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "autoforce",
3
3
  "homepage": "https://sebastianclaros.github.io/autoforce",
4
4
  "private": false,
5
- "version": "0.1.15",
5
+ "version": "0.1.17",
6
6
  "keywords": [
7
7
  "Salesforce",
8
8
  "Automation",