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,88 +1,60 @@
|
|
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 { GraphQLClient } from 'graphql-request';
|
11
2
|
const GITLAB_API = 'https://gitlab.com/api/graphql?remove_deprecated=true';
|
12
3
|
export class GitLabApi {
|
4
|
+
repoVar;
|
5
|
+
projectNumber;
|
6
|
+
graphqlAuth;
|
13
7
|
constructor(token, owner, repo, projectNumber) {
|
14
8
|
this.graphqlAuth = new GraphQLClient(GITLAB_API);
|
15
9
|
this.repoVar = { owner, repo };
|
16
10
|
this.projectNumber = projectNumber;
|
17
11
|
this.graphqlAuth.setHeaders({ authorization: `Bearer ${token}` });
|
18
12
|
}
|
19
|
-
getLabels() {
|
20
|
-
return
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
}
|
28
|
-
}
|
29
|
-
|
30
|
-
return
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
}
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
return
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
}
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
createIssue(title, state, label, body, milestone) {
|
58
|
-
return __awaiter(this, void 0, void 0, function* () {
|
59
|
-
console.log(title, state, label, body, milestone);
|
60
|
-
return { number: 1 };
|
61
|
-
});
|
62
|
-
}
|
63
|
-
moveIssue(issueNumber, state) {
|
64
|
-
return __awaiter(this, void 0, void 0, function* () {
|
65
|
-
console.log(issueNumber, state);
|
66
|
-
return true;
|
67
|
-
});
|
68
|
-
}
|
69
|
-
assignIssueToMe(issueNumber) {
|
70
|
-
return __awaiter(this, void 0, void 0, function* () {
|
71
|
-
console.log(issueNumber);
|
72
|
-
return true;
|
73
|
-
});
|
74
|
-
}
|
75
|
-
getUser() {
|
76
|
-
return __awaiter(this, void 0, void 0, function* () {
|
77
|
-
const query = `{
|
13
|
+
async getLabels() {
|
14
|
+
return [];
|
15
|
+
}
|
16
|
+
async getMilestones() {
|
17
|
+
return [];
|
18
|
+
}
|
19
|
+
async getIssue(issueNumber) {
|
20
|
+
console.log(issueNumber);
|
21
|
+
return {};
|
22
|
+
}
|
23
|
+
async getIssues() {
|
24
|
+
return [];
|
25
|
+
}
|
26
|
+
async getIssuesWithFilter(filter) {
|
27
|
+
return [];
|
28
|
+
}
|
29
|
+
async createLabel(name, color = 'random') {
|
30
|
+
console.log(name, color);
|
31
|
+
return { id: '', name, color };
|
32
|
+
}
|
33
|
+
async createMilestone(title, state = 'open', description, dueOn) {
|
34
|
+
console.log(title, state, description, dueOn);
|
35
|
+
return { id: '', title: '', state: '', url: '' };
|
36
|
+
}
|
37
|
+
async createIssue(title, state, label, body, milestone) {
|
38
|
+
console.log(title, state, label, body, milestone);
|
39
|
+
return { number: 1 };
|
40
|
+
}
|
41
|
+
async moveIssue(issueNumber, state) {
|
42
|
+
console.log(issueNumber, state);
|
43
|
+
return true;
|
44
|
+
}
|
45
|
+
async assignIssueToMe(issueNumber) {
|
46
|
+
console.log(issueNumber);
|
47
|
+
return true;
|
48
|
+
}
|
49
|
+
async getUser() {
|
50
|
+
const query = `{
|
78
51
|
viewer {
|
79
52
|
login
|
80
53
|
id
|
81
54
|
}
|
82
55
|
}`;
|
83
|
-
|
84
|
-
|
85
|
-
});
|
56
|
+
const { viewer } = await this.graphqlAuth.request(query);
|
57
|
+
return viewer;
|
86
58
|
}
|
87
59
|
// async request ( document: string, variables: Record<string, AnyValue> ) {
|
88
60
|
// return await request({
|
@@ -92,43 +64,35 @@ export class GitLabApi {
|
|
92
64
|
// headers: this.headers
|
93
65
|
// })
|
94
66
|
// }
|
95
|
-
graphqlQuery(query, vars) {
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
}
|
112
|
-
|
113
|
-
|
114
|
-
});
|
115
|
-
}
|
116
|
-
createPullRequest(branchName, title, body) {
|
117
|
-
return __awaiter(this, void 0, void 0, function* () {
|
118
|
-
const query = `mutation($branchName: ID!, $title: String!, $body: String!) {
|
67
|
+
async graphqlQuery(query, vars) {
|
68
|
+
const result = await this.graphqlAuth.request(query, vars);
|
69
|
+
return result;
|
70
|
+
// let toProcess = result[endpoint]
|
71
|
+
// let returnVal = toProcess.nodes
|
72
|
+
// let pageInfo = toProcess.pageInfo
|
73
|
+
// let curPage = pageInfo.endCursor
|
74
|
+
// if ( pageInfo.hasNextPage ) {
|
75
|
+
// curPage = pageInfo.endCursor
|
76
|
+
// result = await this.graphql.request(query, vars)
|
77
|
+
// returnVal = returnVal.concat(result[endpoint].nodes)
|
78
|
+
// pageInfo = result[endpoint].pageInfo
|
79
|
+
// }
|
80
|
+
// return returnVal
|
81
|
+
}
|
82
|
+
async getRepository() {
|
83
|
+
}
|
84
|
+
async createPullRequest(branchName, title, body) {
|
85
|
+
const query = `mutation($branchName: ID!, $title: String!, $body: String!) {
|
119
86
|
|
120
87
|
}`;
|
121
|
-
|
122
|
-
|
123
|
-
});
|
88
|
+
await this.graphqlQuery(query, { branchName, title, body });
|
89
|
+
return true;
|
124
90
|
}
|
125
|
-
assignBranchToIssue(issueNumber, branchName, commitSha) {
|
126
|
-
|
127
|
-
const query = `mutation($branchName: ID!, $issueNumber: Int!, $commitSha: String!) {
|
91
|
+
async assignBranchToIssue(issueNumber, branchName, commitSha) {
|
92
|
+
const query = `mutation($branchName: ID!, $issueNumber: Int!, $commitSha: String!) {
|
128
93
|
|
129
94
|
}`;
|
130
|
-
|
131
|
-
|
132
|
-
});
|
95
|
+
await this.graphqlQuery(query, { branchName, issueNumber: Number.parseInt(issueNumber), commitSha });
|
96
|
+
return true;
|
133
97
|
}
|
134
98
|
}
|
package/lib/helpers/lwc.js
CHANGED
@@ -1,12 +1,3 @@
|
|
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 sf from "./connect.js";
|
11
2
|
import { default as templateGenerator } from "./template.js";
|
12
3
|
import { DICTIONARY_FOLDER, getModelFolders } from "./util.js";
|
@@ -18,18 +9,16 @@ function getTemplateEngine() {
|
|
18
9
|
return _templateEngine;
|
19
10
|
}
|
20
11
|
import { sortByName, splitFilename } from "./util.js";
|
21
|
-
function getMetadata(lwc) {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
return [];
|
32
|
-
});
|
12
|
+
async function getMetadata(lwc) {
|
13
|
+
try {
|
14
|
+
await sf.connect();
|
15
|
+
const lwcRecords = await sf.getLwc(lwc);
|
16
|
+
return Array.isArray(lwcRecords) ? lwcRecords : [lwcRecords];
|
17
|
+
}
|
18
|
+
catch (e) {
|
19
|
+
console.error(e);
|
20
|
+
}
|
21
|
+
return [];
|
33
22
|
}
|
34
23
|
function getLwc(files) {
|
35
24
|
const items = new Set();
|
@@ -41,34 +30,32 @@ function getLwc(files) {
|
|
41
30
|
}
|
42
31
|
return [...items.values()];
|
43
32
|
}
|
44
|
-
function executeLwc(items, filename, folder) {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
templateEngine.render(context, {
|
59
|
-
helpers: {}
|
60
|
-
});
|
61
|
-
templateEngine.save(context.Name, DICTIONARY_FOLDER + "/lwc");
|
62
|
-
}
|
63
|
-
// Arma el documento indice del grupo de lwc
|
64
|
-
contexts.sort(sortByName);
|
65
|
-
templateEngine.read("lwcs");
|
66
|
-
const lwcContext = { lwc: contexts };
|
67
|
-
templateEngine.render(lwcContext, {
|
33
|
+
async function executeLwc(items, filename, folder) {
|
34
|
+
const templateEngine = getTemplateEngine();
|
35
|
+
if (items.length === 0) {
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
// Busca la metadata
|
39
|
+
const contexts = await getMetadata(items);
|
40
|
+
if (!contexts || contexts.length === 0) {
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
// Arma el diccionario de cada LWC
|
44
|
+
templateEngine.read("lwc");
|
45
|
+
for (const context of contexts) {
|
46
|
+
templateEngine.render(context, {
|
68
47
|
helpers: {}
|
69
48
|
});
|
70
|
-
templateEngine.save(
|
49
|
+
templateEngine.save(context.Name, DICTIONARY_FOLDER + "/lwc");
|
50
|
+
}
|
51
|
+
// Arma el documento indice del grupo de lwc
|
52
|
+
contexts.sort(sortByName);
|
53
|
+
templateEngine.read("lwcs");
|
54
|
+
const lwcContext = { lwc: contexts };
|
55
|
+
templateEngine.render(lwcContext, {
|
56
|
+
helpers: {}
|
71
57
|
});
|
58
|
+
templateEngine.save(filename, folder);
|
72
59
|
}
|
73
60
|
const lwcModule = {
|
74
61
|
getItems: getLwc,
|
package/lib/helpers/object.js
CHANGED
@@ -1,12 +1,3 @@
|
|
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 sf from "./connect.js";
|
11
2
|
import { default as templateGenerator } from "./template.js";
|
12
3
|
import { DICTIONARY_FOLDER, getModelFolders } from "./util.js";
|
@@ -18,29 +9,25 @@ function getTemplateEngine() {
|
|
18
9
|
return _templateEngine;
|
19
10
|
}
|
20
11
|
import { sortByLabel } from "./util.js";
|
21
|
-
function getMetadata(objetos) {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
return [];
|
32
|
-
});
|
12
|
+
async function getMetadata(objetos) {
|
13
|
+
try {
|
14
|
+
await sf.connect();
|
15
|
+
const objects = await sf.customObjects(objetos);
|
16
|
+
return Array.isArray(objects) ? objects : [objects];
|
17
|
+
}
|
18
|
+
catch (e) {
|
19
|
+
console.error(e);
|
20
|
+
}
|
21
|
+
return [];
|
33
22
|
}
|
34
23
|
function descriptionFormula() {
|
35
|
-
|
36
|
-
return (_a = this.description) === null || _a === void 0 ? void 0 : _a.replaceAll(/[\n\r]/g, "<br/>");
|
24
|
+
return this.description?.replaceAll(/[\n\r]/g, "<br/>");
|
37
25
|
}
|
38
26
|
function isManaged() {
|
39
27
|
return this.fullName.split("__").length == 3;
|
40
28
|
}
|
41
29
|
function isMetadataFormula() {
|
42
|
-
|
43
|
-
return ((_a = this.fullName) === null || _a === void 0 ? void 0 : _a.endsWith("__mdt")) || this.customSettingsType;
|
30
|
+
return this.fullName?.endsWith("__mdt") || this.customSettingsType;
|
44
31
|
}
|
45
32
|
function attributesFormula() {
|
46
33
|
const attributes = [];
|
@@ -103,36 +90,34 @@ function getObjects(files) {
|
|
103
90
|
}
|
104
91
|
return [...items.values()];
|
105
92
|
}
|
106
|
-
function executeObjects(items, filename, folder) {
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
templateEngine.save(context.fullName, DICTIONARY_FOLDER + "/objects");
|
125
|
-
}
|
93
|
+
async function executeObjects(items, filename, folder) {
|
94
|
+
const templateEngine = getTemplateEngine();
|
95
|
+
if (items.length === 0) {
|
96
|
+
return;
|
97
|
+
}
|
98
|
+
// Busca la metadata
|
99
|
+
const contexts = await getMetadata(items);
|
100
|
+
if (!contexts || contexts.length === 0) {
|
101
|
+
return;
|
102
|
+
}
|
103
|
+
// Arma el diccionario de cada Objeto
|
104
|
+
templateEngine.read("object");
|
105
|
+
for (const context of contexts) {
|
106
|
+
if (context.fullName) {
|
107
|
+
templateEngine.render(context, {
|
108
|
+
helpers: { isManaged, descriptionFormula, typeFormula, attributesFormula }
|
109
|
+
});
|
110
|
+
templateEngine.save(context.fullName, DICTIONARY_FOLDER + "/objects");
|
126
111
|
}
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
}
|
134
|
-
templateEngine.save(filename, folder);
|
112
|
+
}
|
113
|
+
// Arma el documento indice del grupo de objetos
|
114
|
+
contexts.sort(sortByLabel);
|
115
|
+
templateEngine.read("objects");
|
116
|
+
const objectContext = { objects: contexts };
|
117
|
+
templateEngine.render(objectContext, {
|
118
|
+
helpers: { isManaged, isMetadataFormula, attributesFormula }
|
135
119
|
});
|
120
|
+
templateEngine.save(filename, folder);
|
136
121
|
}
|
137
122
|
const objectModule = {
|
138
123
|
getItems: getObjects,
|
package/lib/helpers/openai.js
CHANGED
@@ -1,29 +1,17 @@
|
|
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 OpenAI from 'openai';
|
11
2
|
const client = new OpenAI({
|
12
3
|
apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
|
13
4
|
});
|
14
|
-
export function getCommitMessage() {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
}
|
25
|
-
return null;
|
26
|
-
});
|
5
|
+
export async function getCommitMessage() {
|
6
|
+
if (process.env['OPENAI_API_KEY']) {
|
7
|
+
const params = {
|
8
|
+
messages: [{ role: 'user', content: 'Say this is a test' }],
|
9
|
+
model: 'gpt-3.5-turbo',
|
10
|
+
};
|
11
|
+
const chatCompletion = await client.chat.completions.create(params);
|
12
|
+
return chatCompletion.choices[0].message?.content;
|
13
|
+
}
|
14
|
+
return null;
|
27
15
|
}
|
28
16
|
/*
|
29
17
|
// getCommitMessage();
|