Skip to content

Commit eacca4b

Browse files
committed
Added github workflows
1 parent c6603aa commit eacca4b

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

src/action.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,13 @@ const getMetadataFromIssueBody = (body) => {
2828
}
2929
}
3030

31-
class Component {
32-
constructor(slug, metadata, issueNumber, drifted, error) {
33-
this.slug = slug;
34-
this.metadata = metadata;
35-
this.issueNumber = issueNumber;
36-
this.drifted = drifted;
37-
this.error = error;
38-
}
39-
}
40-
4131
const mapOpenGitHubIssuesToComponents = async (octokit, context) => {
4232
const repository = context.repo;
4333

4434
let per_page = 100; // Max allowed value per page
4535
let page = 1;
4636
let componentsToIssues = {};
4737
let componentsToMetadata = {};
48-
let components = {};
4938
let isContinue = true;
5039

5140
while (isContinue) {
@@ -60,14 +49,13 @@ const mapOpenGitHubIssuesToComponents = async (octokit, context) => {
6049
isContinue = false;
6150
} else {
6251
const driftDetectionIssues = response.data
63-
.filter(issue => issue.title.startsWith('Drift Detected in'));
52+
.filter(issue => issue.title.startsWith('Drift Detected in') || issue.title.startsWith('Failure Detected in'));
6453

6554
for (let issue of driftDetectionIssues) {
6655
const metadata = getMetadataFromIssueBody(issue.body);
6756
const slug = `${metadata.stack}-${metadata.component}`
6857
componentsToIssues[slug] = issue.number;
6958
componentsToMetadata[slug] = metadata;
70-
components[slug] = new Component(slug, metadata, issue.number, true, false)
7159
}
7260

7361
page++;
@@ -77,7 +65,6 @@ const mapOpenGitHubIssuesToComponents = async (octokit, context) => {
7765
return {
7866
componentsToIssues: componentsToIssues,
7967
componentsToMetadata: componentsToMetadata,
80-
components: components
8168
};
8269
}
8370

@@ -87,7 +74,6 @@ const readMetadataFromPlanArtifacts = async () => {
8774

8875
let componentsToState = {};
8976
let componentsToMetadata = {};
90-
let components = {};
9177

9278
for (let i = 0; i < metadataFiles.length; i++) {
9379
const metadata = JSON.parse(fs.readFileSync(metadataFiles[i], 'utf8'));
@@ -99,13 +85,11 @@ const readMetadataFromPlanArtifacts = async () => {
9985
error: metadata.error
10086
};
10187
componentsToMetadata[slug] = metadata;
102-
components[slug] = new Component(slug, metadata, null, metadata.drifted, metadata.error)
10388
}
10489

10590
return {
10691
componentsToState: componentsToState,
10792
componentsToMetadata: componentsToMetadata,
108-
components: components
10993
};
11094
}
11195

@@ -241,15 +225,15 @@ const convertTeamsToUsers = async (octokit, orgName, teams) => {
241225
return users;
242226
}
243227

244-
const createIssues = async (octokit, context, maxOpenedIssues, labels, users, componentsToIssues, componentsCandidatesToCreateIssue, componentsCandidatesToCloseIssue) => {
228+
const createIssues = async (octokit, context, maxOpenedIssues, labels, users, componentsToIssues, componentsCandidatesToCreateIssue, componentsCandidatesToCloseIssue, erroredComponents) => {
245229
const repository = context.repo;
246230
const numberOfMaximumPotentialIssuesThatCanBeCreated = Math.max(0, maxOpenedIssues - Object.keys(componentsToIssues).length + componentsCandidatesToCloseIssue.length);
247231
const numOfIssuesToCreate = Math.min(numberOfMaximumPotentialIssuesThatCanBeCreated, componentsCandidatesToCreateIssue.length);
248232
const componentsToNewlyCreatedIssues = {};
249233

250234
for (let i = 0; i < numOfIssuesToCreate; i++) {
251235
const slug = componentsCandidatesToCreateIssue[i];
252-
const issueTitle = `Drift Detected in \`${slug}\``;
236+
const issueTitle = erroredComponents.hasOwnProperty(slug) ? `Failure Detected in \`${slug}\`` : `Drift Detected in \`${slug}\``;
253237
const issueDescription = fs.readFileSync(`issue-description-${slug}.md`, 'utf8');
254238

255239
const newIssue = await octokit.rest.issues.create({
@@ -423,7 +407,7 @@ const runAction = async (octokit, context, parameters) => {
423407
let users = assigneeUsers.concat(usersFromTeams);
424408
users = [...new Set(users)]; // get unique set
425409

426-
const componentsToNewlyCreatedIssues = await createIssues(octokit, context, maxOpenedIssues, labels, users, componentsToIssueNumber, componentsCandidatesToCreateIssue, componentsCandidatesToCloseIssue);
410+
const componentsToNewlyCreatedIssues = await createIssues(octokit, context, maxOpenedIssues, labels, users, componentsToIssueNumber, componentsCandidatesToCreateIssue, componentsCandidatesToCloseIssue, erroredComponents);
427411

428412
await updateIssues(octokit, context, componentsToIssueNumber, componentsToUpdateExistingIssue);
429413

0 commit comments

Comments
 (0)