forked from vn7n24fzkq/github-profile-summary-cards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: Add eslint to project (vn7n24fzkq#37)
* Code refactor for lint * Add babel for unit test env
- Loading branch information
1 parent
60037b0
commit 6c9a63c
Showing
34 changed files
with
5,899 additions
and
1,783 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["@babel/preset-env"] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"env": { | ||
"node": true, | ||
"es2021": true | ||
}, | ||
"plugins": ["prettier"], | ||
"extends": ["google", "plugin:prettier/recommended"], | ||
"rules": { | ||
"prettier/prettier": "error", | ||
"require-jsdoc": 0 | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 12, | ||
"sourceType": "module" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Ignore artifacts: | ||
build | ||
coverage |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 4, | ||
"semi": false, | ||
"singleQuote": true | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"collectCoverage": true, | ||
"moduleFileExtensions": ["js", "mjs"], | ||
"transform": { | ||
"^.+\\.js$": "babel-jest", | ||
"^.+\\.mjs$": "babel-jest" | ||
}, | ||
"setupFilesAfterEnv": ["./tests/setupTests.js"], | ||
"testRegex": "./tests/.*\\.test.js$" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,46 @@ | ||
{ | ||
"name": "github-profile-summary-cards", | ||
"version": "0.2.6", | ||
"description": "Generate github profile summary cards", | ||
"main": "src/app.js", | ||
"scripts": { | ||
"run": "node src/app.js", | ||
"build": "ncc build src/app.js", | ||
"test": "jest --passWithNoTests " | ||
}, | ||
"keywords": [ | ||
"github" | ||
], | ||
"author": "vn7 <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@actions/core": "^1.2.6", | ||
"@actions/github": "^4.0.0", | ||
"axios": "^0.21.1", | ||
"childprocess": "^2.0.2", | ||
"d3": "^5.16.0", | ||
"dotenv": "^8.2.0", | ||
"jsdom": "^16.4.0", | ||
"moment": "^2.27.0", | ||
"number-abbreviate": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@vercel/ncc": "^0.27.0", | ||
"axios-mock-adapter": "^1.18.2", | ||
"jest": "^26.4.2", | ||
"pre-commit": "^1.2.2" | ||
}, | ||
"pre-commit": [ | ||
"test" | ||
] | ||
"name": "github-profile-summary-cards", | ||
"version": "0.2.6", | ||
"description": "Generate github profile summary cards", | ||
"main": "src/app.js", | ||
"scripts": { | ||
"run": "node src/app.js", | ||
"build": "ncc build src/app.js", | ||
"test": "jest --passWithNoTests " | ||
}, | ||
"keywords": [ | ||
"github" | ||
], | ||
"author": "vn7 <[email protected]>", | ||
"license": "MIT", | ||
"type": "module", | ||
"dependencies": { | ||
"@actions/core": "^1.2.6", | ||
"@actions/github": "^4.0.0", | ||
"axios": "^0.21.1", | ||
"childprocess": "^2.0.2", | ||
"d3": "^5.16.0", | ||
"dotenv": "^8.2.0", | ||
"jsdom": "^16.4.0", | ||
"moment": "^2.27.0", | ||
"number-abbreviate": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.13.10", | ||
"@babel/node": "^7.13.12", | ||
"@babel/preset-env": "^7.13.12", | ||
"@vercel/ncc": "^0.27.0", | ||
"axios-mock-adapter": "^1.18.2", | ||
"eslint": "^7.22.0", | ||
"eslint-config-google": "^0.14.0", | ||
"eslint-config-prettier": "^8.1.0", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"jest": "^26.4.2", | ||
"pre-commit": "^1.2.2", | ||
"prettier": "2.2.1", | ||
"regenerator-runtime": "^0.13.7" | ||
}, | ||
"pre-commit": [ | ||
"test" | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,126 +1,137 @@ | ||
const core = require("@actions/core"); | ||
const createProfileDetailsCard = require("./cards/profile-details-card"); | ||
const createReposPerLanguageCard = require("./cards/repos-per-language-card"); | ||
const createCommitsPerLanguageCard = require("./cards/most-commit-lauguage-card"); | ||
const createStatsCard = require("./cards/stats-card"); | ||
const createProductiveTimeCard = require("./cards/productive-time-card"); | ||
const { spawn } = require("child_process"); | ||
const { outputPath, generatePreviewMarkdown } = require("./utils/file-writer"); | ||
import { | ||
info, | ||
getInput, | ||
error as _error, | ||
warning, | ||
setFailed, | ||
} from '@actions/core' | ||
import createProfileDetailsCard from './cards/profile-details-card.js' | ||
import createReposPerLanguageCard from './cards/repos-per-language-card.js' | ||
import createCommitsPerLanguageCard from './cards/most-commit-lauguage-card.js' | ||
import createStatsCard from './cards/stats-card.js' | ||
import createProductiveTimeCard from './cards/productive-time-card.js' | ||
import { spawn } from 'child_process' | ||
import { outputPath, generatePreviewMarkdown } from './utils/file-writer.js' | ||
import dotenv from 'dotenv' | ||
|
||
dotenv.config() | ||
|
||
const execCmd = (cmd, args = []) => | ||
new Promise((resolve, reject) => { | ||
const app = spawn(cmd, args, { stdio: "pipe" }); | ||
let stdout = ""; | ||
app.stdout.on("data", (data) => { | ||
stdout = data; | ||
}); | ||
app.on("close", (code) => { | ||
if (code !== 0 && !stdout.includes("nothing to commit")) { | ||
err = new Error( | ||
`${cmd} ${args} \n ${stdout} \n Invalid status code: ${code}` | ||
); | ||
err.code = code; | ||
return reject(err); | ||
} | ||
return resolve(code); | ||
}); | ||
app.on("error", reject); | ||
}); | ||
new Promise((resolve, reject) => { | ||
const app = spawn(cmd, args, { stdio: 'pipe' }) | ||
let stdout = '' | ||
app.stdout.on('data', (data) => { | ||
stdout = data | ||
}) | ||
app.on('close', (code) => { | ||
if (code !== 0 && !stdout.includes('nothing to commit')) { | ||
err = new Error( | ||
`${cmd} ${args} \n ${stdout} \n Invalid status code: ${code}` | ||
) | ||
err.code = code | ||
return reject(err) | ||
} | ||
return resolve(code) | ||
}) | ||
app.on('error', reject) | ||
}) | ||
|
||
const commitFile = async () => { | ||
await execCmd("git", [ | ||
"config", | ||
"--global", | ||
"user.email", | ||
"[email protected]", | ||
]); | ||
await execCmd("git", [ | ||
"config", | ||
"--global", | ||
"user.name", | ||
"profile-summary-cards[bot]", | ||
]); | ||
await execCmd("git", ["add", outputPath]); | ||
await execCmd("git", ["commit", "-m", "Generate profile summary cards"]); | ||
await execCmd("git", ["push"]); | ||
}; | ||
await execCmd('git', [ | ||
'config', | ||
'--global', | ||
'user.email', | ||
'[email protected]', | ||
]) | ||
await execCmd('git', [ | ||
'config', | ||
'--global', | ||
'user.name', | ||
'profile-summary-cards[bot]', | ||
]) | ||
await execCmd('git', ['add', outputPath]) | ||
await execCmd('git', ['commit', '-m', 'Generate profile summary cards']) | ||
await execCmd('git', ['push']) | ||
} | ||
|
||
// main | ||
const main = async () => { | ||
core.info(`Start...`); | ||
let username = process.argv[2]; | ||
let isInGithubAction = false; | ||
info(`Start...`) | ||
let username = process.argv[2] | ||
let isInGithubAction = false | ||
|
||
if (process.argv.length == 2) { | ||
try { | ||
username = core.getInput("USERNAME"); | ||
isInGithubAction = true; | ||
} catch (error) { | ||
throw Error(error.message); | ||
} | ||
} | ||
try { | ||
// remove old output | ||
if (isInGithubAction) { | ||
core.info(`Remove old cards...`); | ||
await execCmd("sudo", ["rm", "-rf", outputPath]); | ||
} | ||
try { | ||
core.info(`Creating ProfileDetailsCard...`); | ||
await createProfileDetailsCard(username); | ||
} catch (error) { | ||
core.error(`Error when creating ProfileDetailsCard \n${error.stack}`); | ||
} | ||
try { | ||
core.info(`Creating ReposPerLanguageCard...`); | ||
await createReposPerLanguageCard(username); | ||
} catch (error) { | ||
core.error(`Error when creating ReposPerLanguageCard \n${error.stack}`); | ||
} | ||
try { | ||
core.info(`Creating CommitsPerLanguageCard...`); | ||
await createCommitsPerLanguageCard(username); | ||
} catch (error) { | ||
core.error(`Error when creating CommitsPerLanguageCard \n${error.stack}`); | ||
} | ||
try { | ||
core.info(`Creating StatsCard...`); | ||
await createStatsCard(username); | ||
} catch (error) { | ||
core.error(`Error when creating StatsCard \n${error.stack}`); | ||
} | ||
try { | ||
core.info(`Creating ProductiveTimeCard...`); | ||
await createProductiveTimeCard(username); | ||
} catch (error) { | ||
core.error(`Error when creating ProductiveTimeCard \n${error.stack}`); | ||
if (process.argv.length == 2) { | ||
try { | ||
username = getInput('USERNAME') | ||
isInGithubAction = true | ||
} catch (error) { | ||
throw Error(error.message) | ||
} | ||
} | ||
try { | ||
core.info(`Creating preview markdown...`); | ||
await generatePreviewMarkdown(isInGithubAction); | ||
} catch (error) { | ||
core.error(`Error when creating preview markdown \n${error.stack}`); | ||
} | ||
if (isInGithubAction) { | ||
core.info(`Commit file...`); | ||
let retry = 0; | ||
let maxRetry = 3; | ||
while (retry < maxRetry) { | ||
retry += 1; | ||
// remove old output | ||
if (isInGithubAction) { | ||
info(`Remove old cards...`) | ||
await execCmd('sudo', ['rm', '-rf', outputPath]) | ||
} | ||
try { | ||
await commitFile(); | ||
info(`Creating ProfileDetailsCard...`) | ||
await createProfileDetailsCard(username) | ||
} catch (error) { | ||
if (retry == maxRetry) { | ||
throw error; | ||
} | ||
core.warning(`Commit failed. Retry...`); | ||
_error(`Error when creating ProfileDetailsCard \n${error.stack}`) | ||
} | ||
} | ||
try { | ||
info(`Creating ReposPerLanguageCard...`) | ||
await createReposPerLanguageCard(username) | ||
} catch (error) { | ||
_error(`Error when creating ReposPerLanguageCard \n${error.stack}`) | ||
} | ||
try { | ||
info(`Creating CommitsPerLanguageCard...`) | ||
await createCommitsPerLanguageCard(username) | ||
} catch (error) { | ||
_error( | ||
`Error when creating CommitsPerLanguageCard \n${error.stack}` | ||
) | ||
} | ||
try { | ||
info(`Creating StatsCard...`) | ||
await createStatsCard(username) | ||
} catch (error) { | ||
_error(`Error when creating StatsCard \n${error.stack}`) | ||
} | ||
try { | ||
info(`Creating ProductiveTimeCard...`) | ||
await createProductiveTimeCard(username) | ||
} catch (error) { | ||
_error(`Error when creating ProductiveTimeCard \n${error.stack}`) | ||
} | ||
try { | ||
info(`Creating preview markdown...`) | ||
await generatePreviewMarkdown(isInGithubAction) | ||
} catch (error) { | ||
_error(`Error when creating preview markdown \n${error.stack}`) | ||
} | ||
if (isInGithubAction) { | ||
info(`Commit file...`) | ||
let retry = 0 | ||
const maxRetry = 3 | ||
while (retry < maxRetry) { | ||
retry += 1 | ||
try { | ||
await commitFile() | ||
} catch (error) { | ||
if (retry == maxRetry) { | ||
throw error | ||
} | ||
warning(`Commit failed. Retry...`) | ||
} | ||
} | ||
} | ||
} catch (error) { | ||
_error(error) | ||
setFailed(error.message) | ||
} | ||
} catch (error) { | ||
core.error(error); | ||
core.setFailed(error.message); | ||
} | ||
}; | ||
} | ||
|
||
main(); | ||
main() |
Oops, something went wrong.