From 1ab721104467d33a884c873f238a1185e9b22a4e Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Sun, 18 Oct 2020 14:40:32 +0200 Subject: [PATCH] Integration check changes --- .github/pull_request_template.md | 12 ++++++++ .github/workflows/analysis.yml | 5 ++-- README.md | 2 +- tests/metrics.mjs | 48 ++++++++++++++++++-------------- utils/build.mjs | 5 ++-- 5 files changed, 45 insertions(+), 27 deletions(-) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..d7e1989a --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,12 @@ + + +**Pull request description** + + +**Additional context and screenshots** + diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index 7b4aa9bb..f2f84473 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -18,7 +18,6 @@ jobs: uses: github/codeql-action/init@v1 with: languages: javascript + config-file: ./.github/config/codeql.yml - name: Analyze - uses: github/codeql-action/analyze@v1 - with: - config-file: ./.github/config/codeql.yml \ No newline at end of file + uses: github/codeql-action/analyze@v1 \ No newline at end of file diff --git a/README.md b/README.md index 37aea0e7..0bd0f038 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 📊 GitHub metrics -![Build](https://github.com/lowlighter/metrics/workflows/Build/badge.svg) +![Build](https://github.com/lowlighter/metrics/workflows/Build/badge.svg) ![Analysis](https://github.com/lowlighter/metrics/workflows/Analysis/badge.svg) Generates your own GitHub metrics as an SVG image to put them on your profile page or elsewhere ! See what it looks like below : diff --git a/tests/metrics.mjs b/tests/metrics.mjs index ce703699..a7a09f43 100644 --- a/tests/metrics.mjs +++ b/tests/metrics.mjs @@ -8,32 +8,38 @@ import libxmljs from "libxmljs" import url from "url" -//Dirname +//Initialization const __dirname = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "..", "action") - -//Die on unhandled rejections process.on("unhandledRejection", error => { throw error }) -//Load GitHub handlers - const token = process.argv.slice(2)[0] - const graphql = octokit.graphql.defaults({headers:{authorization: `token ${token}`}}) - const rest = new OctokitRest.Octokit({auth:token}) +/** Test function */ + export default async function test() { + //Load GitHub handlers + const token = process.argv.slice(2)[0] + const graphql = octokit.graphql.defaults({headers:{authorization: `token ${token}`}}) + const rest = new OctokitRest.Octokit({auth:token}) -//Load svg template, style and query - const [template, style, query] = await Promise.all(["template.svg", "style.css", "query.graphql"].map(async file => `${await fs.promises.readFile(path.join("src", file))}`)) + //Load svg template, style and query + const [template, style, query] = await Promise.all(["template.svg", "style.css", "query.graphql"].map(async file => `${await fs.promises.readFile(path.join("src", file))}`)) -//Compute render - const rendered = await metrics({login:"lowlighter", q:{}}, {template, style, query, graphql, rest, plugins:{}}) + //Compute render + const rendered = await metrics({login:"lowlighter", q:{}}, {template, style, query, graphql, rest, plugins:{}}) -//Ensure it's a well-formed SVG image - const parsed = libxmljs.parseXml(rendered) - if (parsed.errors.length) - throw new Error(`Malformed SVG : \n${parsed.errors.join("\n")}`) + //Ensure it's a well-formed SVG image + const parsed = libxmljs.parseXml(rendered) + if (parsed.errors.length) + throw new Error(`Malformed SVG : \n${parsed.errors.join("\n")}`) -//Ensure that action has been rebuild - const action = `${await fs.promises.readFile(`${__dirname}/dist/index.js`)}` - const code = await build() - if (action !== code) - throw new Error(`GitHub Action has not been rebuild. Run "npm run build" to solve this issue`) + //Ensure that action has been rebuild + const action = `${await fs.promises.readFile(`${__dirname}/dist/index.js`)}` + const code = await build() + if (action !== code) + throw new Error(`GitHub Action has not been rebuild. Run "npm run build" to solve this issue`) + } - console.log("Test success !") \ No newline at end of file + //Main + if (/metrics.mjs/.test(process.argv[1])) { + //Test + await test() + console.log("Test success !") + } diff --git a/utils/build.mjs b/utils/build.mjs index 263d0ff2..fba883c6 100644 --- a/utils/build.mjs +++ b/utils/build.mjs @@ -4,8 +4,9 @@ import url from "url" import ncc from "@vercel/ncc" -//Dirname +//Initialization const __dirname = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "..", "action") + process.on("unhandledRejection", error => { throw error }) /** Build function */ export default async function build() { @@ -35,5 +36,5 @@ if (/build.mjs/.test(process.argv[1])) { //Save build await fs.promises.writeFile(`${__dirname}/dist/index.js`, await build()) - console.log("Build successful !") + console.log("Build success !") } \ No newline at end of file