Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github-stats-box

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github-stats-box - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

.github/workflows/run.yml

56

index.js

@@ -5,3 +5,3 @@ #!/usr/bin/env node

require('dotenv').config();
const { GistBox } = require('gist-box');
const { request } = require('@octokit/request');
const { userInfoFetcher, totalCommitsFetcher } = require('./fetch');

@@ -14,4 +14,16 @@

async function main() {
const stats = await getStats();
await updateGist(stats);
if (!githubToken) {
throw new Error('GH_TOKEN is not defined');
}
let stats;
try {
stats = await getStats();
} catch (e) {
throw new Error(`cannot retrieve statistics: ${e.message}`);
}
try {
await updateGist(stats);
} catch (e) {
throw new Error(`cannot update gist: ${e.message}`);
}
}

@@ -66,18 +78,30 @@

try {
const box = new GistBox({ id: gistId, token: githubToken });
await box.update({
filename: `${stats.name}'s GitHub Stats`,
description: 'Generated',
content: gistContent,
});
} catch (error) {
console.error(`Unable to update gist\n${error}`);
const gist = await request('GET /gists/:gist_id', {
gist_id: gistId,
headers: { authorization: `token ${githubToken}` },
});
const filename = Object.keys(gist.data.files)[0];
if (gist.data.files[filename].content === gistContent) {
console.info('Nothing to update');
return;
}
console.info(`Updated Gist ${gistId} with the following content:\n${gistContent}`);
return request('PATCH /gists/:gist_id', {
files: {
[filename]: {
filename: `${stats.name}'s GitHub Stats`,
content: gistContent,
},
},
gist_id: gistId,
headers: { authorization: `token ${githubToken}` },
}).then(() => {
console.info(`Updated Gist ${gistId} with the following content:\n${gistContent}`);
});
}
(async () => {
await main();
})();
main().catch((err) => {
console.error(err.message);
process.exit(1);
});
{
"name": "github-stats-box",
"version": "0.1.1",
"version": "0.1.2",
"description": "Update a gist to contain your GitHub stats",

@@ -24,5 +24,5 @@ "author": "bokub",

"dependencies": {
"@octokit/request": "^5.4.7",
"axios": "^0.19.2",
"dotenv": "8.2.0",
"gist-box": "^0.3.1"
"dotenv": "8.2.0"
},

@@ -29,0 +29,0 @@ "devDependencies": {

<p align="center">
<a href="https://gist.github.com/bokub/387aeb084c3433e24a11b36660ba9937">
<img src="https://user-images.githubusercontent.com/17952318/90407883-52b56000-e0a7-11ea-9da4-d9fac75372c1.png">
<a href="https://gist.github.com/bokub/1cc900d92b9acc15786d7553b46a2cdf">
<img src="https://raw.githubusercontent.com/bokub/github-stats-box/images/screenshot.png">
</a>

@@ -11,47 +11,21 @@ <h3 align="center">github-stats-box</h3>

## Setup
## Prep work
### Prep work
1. Create a new public GitHub Gist (https://gist.github.com/new)
2. Create a token with the `gist` scope and copy it (https://github.com/settings/tokens/new)
1. [Create a new public GitHub Gist](https://gist.github.com/new) (the gist description will be displayed on top of your pinned Gist)
2. [Create a token](https://github.com/settings/tokens/new) with the `gist` scope and copy it
## Project setup
### Project setup
1. Fork this repository
2. From your new fork, go to **Settings > Secrets**
3. Add the following secrets using the **New secret** button:
3. Add the following secret using the **New secret** button:
- **GH_TOKEN:** The GitHub token generated above.
- **GIST_ID:** The ID portion from your gist url: `https://gist.github.com/bokub/`**`387aeb084c3433e24a11b36660ba9937`**.
- **ALL_COMMITS:** Boolean value, If `true` it will count all commits instead of last year commits
4. Go to the **Actions** tab of your fork
5. Click **set up a workflow yourself**
6. Copy-paste this workflow:
4. Go to the **Actions** tab of your fork and click the "enable" button
5. Edit the environment variables at the end of the file `.github/workflows/run.yml`
```yaml
name: Update Github Stats Gist
on:
schedule:
- cron: '0 * * * *'
push:
branches: master
- **GIST_ID:** The ID portion from your gist url: `https://gist.github.com/bokub/`**`1cc900d92b9acc15786d7553b46a2cdf`**.
- **ALL_COMMITS:** Boolean value, If `true` it will count all commits instead of last year commits
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v1
with:
node-version: 12
- run: npx github-stats-box
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GIST_ID: ${{ secrets.GIST_ID }}
ALL_COMMITS: ${{ secrets.ALL_COMMITS }}
```
7. Click **Start commit** then **Commit new file** to save
That's it! You Gist will be updated immediately, and every hour after that
That's it! You gist will be updated immediately, and every hour after that
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc