commit 8d1f197f9cd36d448248cbfccc95fcf2a24b36c6 Author: Chocobozzz Date: Mon Feb 8 14:27:32 2021 +0100 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..66ee735 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/node_modules/ +/.env diff --git a/index.js b/index.js new file mode 100644 index 0000000..7bce028 --- /dev/null +++ b/index.js @@ -0,0 +1,100 @@ +'use strict' + +require('dotenv').config() + +const { graphql } = require('@octokit/graphql') + +if (process.argv.length !== 4) { + console.error('Bad command line (node command owner name)') + process.exit(0) +} + +const owner = process.argv[2] +const name = process.argv[3] + +const graphqlWithAuth = graphql.defaults({ + headers: { + authorization: `token ${process.env.GITHUB_TOKEN}` + }, +}); + +async function run () { + const closed = await countIssuesAndPRs('CLOSED') + const opened = await countIssuesAndPRs('OPEN') + + const repoStats = await repositoryStats() + + const result = { + closedIssues: closed.repository.issues.totalCount, + closedPullRequests: closed.repository.pullRequests.totalCount, + openedIssues: opened.repository.issues.totalCount, + openedPullRequests: opened.repository.pullRequests.totalCount, + collaborators: repoStats.repository.collaborators.totalCount, + commitComments: repoStats.repository.commitComments.totalCount, + stargazers: repoStats.repository.stargazerCount, + watchers: repoStats.repository.watchers.totalCount, + releases: repoStats.repository.releases.totalCount, + collaborators: repoStats.repository.collaborators.totalCount, + commits: repoStats.repository.object.history.totalCount, + forkCount: repoStats.repository.forkCount + } + + console.log(result) +} + +run() + .catch(err => { + console.error(err) + }) + +function repositoryStats () { + return graphqlWithAuth(` + { + repository(owner: "${owner}", name: "${name}") { + forkCount + + stargazerCount + + watchers { + totalCount + } + + releases { + totalCount + } + + commitComments { + totalCount + } + + collaborators { + totalCount + } + + object(expression:"develop") { + ... on Commit { + history { + totalCount + } + } + } + } + } + `) +} + +function countIssuesAndPRs (state) { + return graphqlWithAuth(` + { + repository(owner: "${owner}", name: "${name}") { + issues (states: [ ${state} ]) { + totalCount + } + + pullRequests (states: [ ${state} ]) { + totalCount + } + } + } + `) +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..4499e02 --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "github-stats", + "version": "1.0.0", + "main": "index.js", + "author": "Chocobozzz ", + "license": "MIT", + "dependencies": { + "@octokit/graphql": "^4.6.0", + "dotenv": "^8.2.0" + } +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..6e12f87 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,99 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@octokit/endpoint@^6.0.1": + version "6.0.11" + resolved "https://registry.yarnpkg.com/@octokit/endpoint/-/endpoint-6.0.11.tgz#082adc2aebca6dcefa1fb383f5efb3ed081949d1" + integrity sha512-fUIPpx+pZyoLW4GCs3yMnlj2LfoXTWDUVPTC4V3MUEKZm48W+XYpeWSZCv+vYF1ZABUm2CqnDVf1sFtIYrj7KQ== + dependencies: + "@octokit/types" "^6.0.3" + is-plain-object "^5.0.0" + universal-user-agent "^6.0.0" + +"@octokit/graphql@^4.6.0": + version "4.6.0" + resolved "https://registry.yarnpkg.com/@octokit/graphql/-/graphql-4.6.0.tgz#f9abca55f82183964a33439d5264674c701c3327" + integrity sha512-CJ6n7izLFXLvPZaWzCQDjU/RP+vHiZmWdOunaCS87v+2jxMsW9FB5ktfIxybRBxZjxuJGRnxk7xJecWTVxFUYQ== + dependencies: + "@octokit/request" "^5.3.0" + "@octokit/types" "^6.0.3" + universal-user-agent "^6.0.0" + +"@octokit/openapi-types@^4.0.0": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-4.0.1.tgz#bafd3d173974827ba0b733fcca7f1860cb71a9aa" + integrity sha512-k2hRcfcLRyPJjtYfJLzg404n7HZ6sUpAWAR/uNI8tf96NgatWOpw1ocdF+WFfx/trO1ivBh7ckynO1rn+xAw/Q== + +"@octokit/request-error@^2.0.0": + version "2.0.5" + resolved "https://registry.yarnpkg.com/@octokit/request-error/-/request-error-2.0.5.tgz#72cc91edc870281ad583a42619256b380c600143" + integrity sha512-T/2wcCFyM7SkXzNoyVNWjyVlUwBvW3igM3Btr/eKYiPmucXTtkxt2RBsf6gn3LTzaLSLTQtNmvg+dGsOxQrjZg== + dependencies: + "@octokit/types" "^6.0.3" + deprecation "^2.0.0" + once "^1.4.0" + +"@octokit/request@^5.3.0": + version "5.4.14" + resolved "https://registry.yarnpkg.com/@octokit/request/-/request-5.4.14.tgz#ec5f96f78333bb2af390afa5ff66f114b063bc96" + integrity sha512-VkmtacOIQp9daSnBmDI92xNIeLuSRDOIuplp/CJomkvzt7M18NXgG044Cx/LFKLgjKt9T2tZR6AtJayba9GTSA== + dependencies: + "@octokit/endpoint" "^6.0.1" + "@octokit/request-error" "^2.0.0" + "@octokit/types" "^6.7.1" + deprecation "^2.0.0" + is-plain-object "^5.0.0" + node-fetch "^2.6.1" + once "^1.4.0" + universal-user-agent "^6.0.0" + +"@octokit/types@^6.0.3", "@octokit/types@^6.7.1": + version "6.8.2" + resolved "https://registry.yarnpkg.com/@octokit/types/-/types-6.8.2.tgz#ce4872e038d6df38b2d3c21bc12329af0b10facb" + integrity sha512-RpG0NJd7OKSkWptiFhy1xCLkThs5YoDIKM21lEtDmUvSpbaIEfrxzckWLUGDFfF8RydSyngo44gDv8m2hHruUg== + dependencies: + "@octokit/openapi-types" "^4.0.0" + "@types/node" ">= 8" + +"@types/node@>= 8": + version "14.14.25" + resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.25.tgz#15967a7b577ff81383f9b888aa6705d43fbbae93" + integrity sha512-EPpXLOVqDvisVxtlbvzfyqSsFeQxltFbluZNRndIb8tr9KiBnYNLzrc1N3pyKUCww2RNrfHDViqDWWE1LCJQtQ== + +deprecation@^2.0.0: + version "2.3.1" + resolved "https://registry.yarnpkg.com/deprecation/-/deprecation-2.3.1.tgz#6368cbdb40abf3373b525ac87e4a260c3a700919" + integrity sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ== + +dotenv@^8.2.0: + version "8.2.0" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a" + integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw== + +is-plain-object@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-5.0.0.tgz#4427f50ab3429e9025ea7d52e9043a9ef4159344" + integrity sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q== + +node-fetch@^2.6.1: + version "2.6.1" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" + integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== + +once@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E= + dependencies: + wrappy "1" + +universal-user-agent@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/universal-user-agent/-/universal-user-agent-6.0.0.tgz#3381f8503b251c0d9cd21bc1de939ec9df5480ee" + integrity sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w== + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" + integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=