Last active
May 22, 2024 16:23
-
-
Save dgzlopes/968daa318ce98eb6773deefce8a82de4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const parseResults = { | |
stacks: [], | |
reporterConfigs: [], | |
timezone: "America/New_York", | |
}; | |
export const handleResults = { | |
eventsPerStack: {}, | |
logs: [], | |
}; | |
export const testResults = { | |
steps: [], | |
logs: [], | |
} | |
function argsToMessage(...args) { | |
return args.map((arg) => JSON.stringify(arg)).join(" "); | |
} | |
console = { | |
log: (...args) => { | |
if (_isTest === true) { | |
testResults.logs.push(argsToMessage(...args)); | |
return | |
} | |
handleResults.logs.push(argsToMessage(...args)); | |
}, | |
error: (...args) => { | |
if (_isTest === true) { | |
testResults.logs.push(argsToMessage(...args)); | |
return | |
} | |
handleResults.logs.push(argsToMessage(...args)); | |
}, | |
}; | |
export const Digest = class Digest { | |
constructor(name, config) { | |
this.name = name; | |
this.config = config; | |
if (_isParse === true) { | |
parseResults.stacks.push(this.name); | |
parseResults.reporterConfigs.push({ | |
cron: this.config.cron, | |
email: this.config.email, | |
stacks: [this.name] | |
}); | |
} | |
} | |
push (value) { | |
if (handleResults.eventsPerStack[this.name] === undefined) { | |
handleResults.eventsPerStack[this.name] = []; | |
} | |
handleResults.eventsPerStack[this.name].push(value); | |
} | |
} | |
export const events = { | |
on (source, callback) { | |
if (_isParse === true) { | |
return | |
} | |
const e = _event; | |
_console.log("Inside"+JSON.stringify(e)) | |
if (e._source === source) { | |
callback(e); | |
} | |
} | |
} | |
export const settings = { | |
setTimezone(tz) { | |
if (_isParse === true) { | |
parseResults.timezone = tz; | |
return | |
} | |
} | |
} | |
export function test(name, callback) { | |
if (_isTest === false) { | |
return; | |
} | |
if (testResults.steps === undefined) { | |
testResults.steps = []; | |
} | |
testResults.steps.push({ | |
level: "info", | |
message: `Running test: ${name}`, | |
detail: "", | |
}); | |
callback(); | |
} | |
export function evalGitHubEvent(event) { | |
return { | |
stacks: _evalGitHubEvent(event) | |
}; | |
} | |
export function genGitHubEvent({ | |
title, | |
reason, | |
type, | |
repository: { | |
owner, | |
name, | |
isPrivate, | |
isFork, | |
}, | |
}) { | |
return { | |
title, | |
url: "", | |
reason, | |
type, | |
repository: { | |
fullName: `${owner}/${name}`, | |
name, | |
url: "", | |
private: isPrivate, | |
description: "", | |
fork: isFork, | |
owner: { | |
login: owner, | |
url: "", | |
type: "", | |
siteAdmin: false, | |
}, | |
}, | |
}; | |
} | |
export function equal(a, b) { | |
if (!Array.isArray(a) || !Array.isArray(b)) { | |
testResults.steps.push({ | |
level: "error", | |
message: "Input must be arrays", | |
detail: `Object A: ${JSON.stringify(a)} !== Object B: ${JSON.stringify(b)}`, | |
}); | |
return; | |
} | |
const areArraysEqual = (arr1, arr2) => { | |
return arr1.length === arr2.length && arr1.every((value) => arr2.includes(value)); | |
}; | |
const keysA = a.sort(); | |
const keysB = b.sort(); | |
if (!areArraysEqual(keysA, keysB)) { | |
testResults.steps.push({ | |
level: "error", | |
message: `Array elements mismatch`, | |
detail: `Array A: ${JSON.stringify(a)} !== Array B: ${JSON.stringify(b)}`, | |
}); | |
return; | |
} | |
testResults.steps.push({ | |
level: "info", | |
message: "Arrays are equal", | |
detail: `Array A: ${JSON.stringify(a)} === Array B: ${JSON.stringify(b)}`, | |
}); | |
} | |
export const GitHubReasons = { | |
Assign: "assign", | |
Author: "author", | |
Comment: "comment", | |
Invitation: "invitation", | |
Manual: "manual", | |
Mention: "mention", | |
ReviewRequested: "review_requested", | |
SecurityAlert: "security_alert", | |
StateChange: "state_change", | |
Subscribed: "subscribed", | |
TeamMention: "team_mention", | |
CiActivity: "ci_activity", | |
}; | |
export const GitHubTypes = { | |
CheckSuite: "CheckSuite", | |
Commit: "Commit", | |
Discussion: "Discussion", | |
Issue: "Issue", | |
PullRequest: "PullRequest", | |
Release: "Release", | |
RepositoryVulnerabilityAlert: "RepositoryVulnerabilityAlert", | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment