Skip to content

Commit

Permalink
Clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
devpow112 committed Dec 19, 2023
1 parent ba9d79e commit 3c5c5e4
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"extends": [
"brightspace/node-config"
],
"rules": {
"comma-dangle": "error"
},
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2020
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
"type": "module",
"scripts": {
"prebuild": "rimraf dist/",
"build": "ncc build src/index.js -m -o dist/",
"build": "ncc build src/index.js --minify --out dist/",
"lint": "npm run lint:eslint",
"lint:eslint": "eslint . --ext .js,.cjs",
"fix": "npm run fix:eslint",
"fix:eslint": "npm run lint:eslint -- --fix",
"test": "npm run lint && npm run test:unit",
"test:unit": "c8 env-cmd -f test/.env mocha"
},
"engines": {
"node": ">=20"
},
"dependencies": {
"@actions/core": "^1",
"@actions/github": "^6",
Expand Down
16 changes: 7 additions & 9 deletions src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ const getContext = (logger) => {

try {
const { repo: { owner, repo }, ref, runId } = gitHubContext;
const {
env: {
GITHUB_WORKFLOW_REF,
GITHUB_RUN_ATTEMPT,
GITHUB_HEAD_REF,
GITHUB_SHA
}
} = process;
const { env: {
GITHUB_WORKFLOW_REF,
GITHUB_RUN_ATTEMPT,
GITHUB_HEAD_REF,
GITHUB_SHA
} } = process;
const [workflowPath] = GITHUB_WORKFLOW_REF.split('@');
const workflowRegex = new RegExp(`^${owner}/${repo}/.github/workflows/`);
const branchRef = GITHUB_HEAD_REF || ref;
Expand All @@ -39,7 +37,7 @@ const getContext = (logger) => {
gitBranch = branchRef.replace(/^refs\/heads\//i, '');
gitSha = GITHUB_SHA;
} catch {
throw new Error('Failed getting GitHub context');
throw new Error('Unable to gather GitHub context');
}

logger.info(`GitHub organization: ${githubOrganization}`);
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { finalize, submit } from './report.js';
const inputs = await getInputs(logger);
const report = await finalize(logger, context, inputs);

await submit(logger, inputs, report);
await submit(logger, context, inputs, report);
} catch (err) {
setFailed(err.message);

Expand Down
30 changes: 16 additions & 14 deletions src/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import fs from 'fs/promises';

const ajv = new Ajv({ verbose: true });

addFormats(ajv, ['date-time', 'uri', 'uuid' ]);
addFormats(ajv, ['date-time', 'uri', 'uuid']);

const gitHubPattern = '[A-Za-z0-9_.-]+';
const nonEmptyStringPattern = '^[^\\s].+[^\\s]$';
const schema = {
type: 'object',
properties: {
Expand All @@ -14,17 +16,17 @@ const schema = {
summary: {
type: 'object',
properties: {
githubOrganization: { type: 'string', pattern: '[A-Za-z0-9_.-]+' },
githubRepository: { type: 'string', pattern: '[A-Za-z0-9_.-]+' },
githubWorkflow: { type: 'string', pattern: '^[^\\s].+[^\\s]$' },
githubOrganization: { type: 'string', pattern: gitHubPattern },
githubRepository: { type: 'string', pattern: gitHubPattern },
githubWorkflow: { type: 'string', pattern: nonEmptyStringPattern },
githubRunId: { type: 'integer', minimum: 0 },
githubRunAttempt: { type: 'integer', minimum: 1 },
gitBranch: { type: 'string', pattern: '^[^\\s].+[^\\s]$' },
gitBranch: { type: 'string', pattern: nonEmptyStringPattern },
gitSha: { type: 'string', pattern: '([A-Fa-f0-9]{40})' },
lmsBuild: { type: 'string', pattern: '([0-9]{2}\\.){3}[0-9]{5}' },
lmsInstance: { type: 'string', format: 'uri' },
operatingSystem: { type: 'string', enum: ['windows', 'linux', 'mac'] },
framework: { type: 'string', pattern: '^[^\\s].+[^\\s]$' },
framework: { type: 'string', pattern: nonEmptyStringPattern },
started: { type: 'string', format: 'date-time' },
totalDuration: { type: 'integer', minimum: 0 },
status: { type: 'string', enum: ['passed', 'failed'] },
Expand Down Expand Up @@ -58,15 +60,15 @@ const schema = {
items: {
type: 'object',
properties: {
name: { type: 'string', pattern: '^[^\\s].+[^\\s]$' },
location: { type: 'string', pattern: '^[^\\s].+[^\\s]$' },
name: { type: 'string', pattern: nonEmptyStringPattern },
location: { type: 'string', pattern: nonEmptyStringPattern },
started: { type: 'string', format: 'date-time' },
duration: { type: 'integer', minimum: 0 },
totalDuration: { type: 'integer', minimum: 0 },
status: { type: 'string', enum: ['passed', 'failed', 'skipped'] },
tool: { type: 'string', pattern: '^[^\\s].+[^\\s]$' },
experience: { type: 'string', pattern: '^[^\\s].+[^\\s]$' },
type: { type: 'string', pattern: '^[^\\s].+[^\\s]$' },
tool: { type: 'string', pattern: nonEmptyStringPattern },
experience: { type: 'string', pattern: nonEmptyStringPattern },
type: { type: 'string', pattern: nonEmptyStringPattern },
browser: { type: 'string', enum: ['chromium', 'firefox ', 'webkit'] },
retries: { type: 'integer', minimum: 0 }
},
Expand Down Expand Up @@ -108,14 +110,14 @@ const finalize = async(logger, context, inputs) => {
throw new Error('Report is not valid');
}

logger.info('Injecting any missing GitHub context');
logger.info('Inject any missing GitHub context');

report.summary = {
...context,
...report.summary
};

logger.info('Validating schema');
logger.info('Validate schema');

if (!validate(report)) {
const message = ajv.errorsText(validate.errors, { dataVar: 'report' });
Expand All @@ -128,7 +130,7 @@ const finalize = async(logger, context, inputs) => {
return report;
};

const submit = async(/*logger, report*/) => {
const submit = async(/*logger, context, inputs, report*/) => {

};

Expand Down

0 comments on commit 3c5c5e4

Please sign in to comment.