Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into maxam2017-master

# Conflicts:
#	.github/workflows/schedule.yml
  • Loading branch information
techinpark committed May 24, 2020
2 parents 2c77148 + f364f89 commit b4425c9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GIST_ID: ${{ secrets.GIST_ID }}
LOCALE: ko-KR
TIMEZONE: Asia/Seoul
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ This project uses GitHub graphQL API to get the commit histories and write into

### Prep work
1. Create a new public GitHub Gist (https://gist.github.com/)
2. Create a token with the `gist` and `repo` scope and copy it. (https://github.com/settings/tokens/new)
1. Create a token with the `gist` and `repo` scope and copy it. (https://github.com/settings/tokens/new)
> enable `repo` scope seems **DANGEROUS**<br/>
> but this GitHub Action only accesses your commit timestamp in repository you contributed.
### Project setup

1. Fork this repo
2. Edit the [environment variable](https://github.com/maxam2017/productive-box/blob/master/.github/workflows/schedule.yml#L17-L18) in `.github/workflows/schedule.yml`:
1. Open the "Actions" tab of your fork and click the "enable" button
1. Edit the [environment variable](https://github.com/maxam2017/productive-box/blob/master/.github/workflows/schedule.yml#L17-L18) in `.github/workflows/schedule.yml`:

- **GIST_ID:** The ID portion from your gist url: `https://gist.github.com/maxam2017/`**`9842e074b8ee46aef76fd0d493bae0ed`**.
- **LOCALE:** The locale of your country, eg. `zh-TW` for Taiwan, `en-US` for America, etc.
- **TIMEZONE:** The timezone of your location, eg. `Asia/Taipei` for Taiwan, `America/New_York` for America in New York, etc.

3. Go to the repo **Settings > Secrets**
4. Add the following environment variables:
1. Go to the repo **Settings > Secrets**
1. Add the following environment variables:
- **GH_TOKEN:** The GitHub token generated above.
5. [Pin the newly created Gist](https://help.github.com/en/github/setting-up-and-managing-your-github-profile/pinning-items-to-your-profile)
1. [Pin the newly created Gist](https://help.github.com/en/github/setting-up-and-managing-your-github-profile/pinning-items-to-your-profile)
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "productive-box",
"version": "1.0.0",
"version": "1.1.0",
"description": "Are you an early 🐤 or a night 🦉? Let's check out in gist",
"author": "maxam2017",
"license": "MIT",
Expand Down
22 changes: 12 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ interface IRepo {
const contributedRepoQuery = createContributedRepoQuery(username);
const repoResponse = await githubQuery(contributedRepoQuery)
.catch(error => console.error(`Unable to get the contributed repo\n${error}`));
const repos: IRepo[] = repoResponse?.data?.user?.repositoriesContributedTo?.nodes.map(repoInfo => ({
name: repoInfo?.name,
owner: repoInfo?.owner?.login,
}));
const repos: IRepo[] = repoResponse?.data?.user?.repositoriesContributedTo?.nodes
.filter(repoInfo => (!repoInfo?.isFork))
.map(repoInfo => ({
name: repoInfo?.name,
owner: repoInfo?.owner?.login,
}));

/**
* Third, get commit time and parse into commit-time/hour diagram
Expand All @@ -51,7 +53,7 @@ interface IRepo {
committedTimeResponseMap.forEach(committedTimeResponse => {
committedTimeResponse?.data?.repository?.ref?.target?.history?.edges.forEach(edge => {
const committedDate = edge?.node?.committedDate;
const timeString = new Date(committedDate).toLocaleTimeString([ process.env.LOCALE, 'en-US' ], { hour12: false });
const timeString = new Date(committedDate).toLocaleTimeString('en-US', { hour12: false, timeZone: process.env.TIMEZONE });
const hour = +(timeString.split(':')[0]);

/**
Expand All @@ -71,16 +73,16 @@ interface IRepo {
if (!sum) return;

const oneDay = [
{ label: '🌞Morning', commits: morning },
{ label: '🌆Daytime', commits: daytime },
{ label: '🌃Evening', commits: evening },
{ label: '🌙Night', commits: night },
{ label: '🌞 Morning', commits: morning },
{ label: '🌆 Daytime', commits: daytime },
{ label: '🌃 Evening', commits: evening },
{ label: '🌙 Night', commits: night },
];

const lines = oneDay.reduce((prev, cur) => {
const percent = cur.commits / sum * 100;
const line = [
`${cur.label}`.padEnd(9),
`${cur.label}`.padEnd(10),
`${cur.commits.toString().padStart(5)} commits`.padEnd(14),
generateBarChart(percent, 21),
String(percent.toFixed(1)).padStart(5) + '%',
Expand Down
3 changes: 2 additions & 1 deletion src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export const userInfoQuery = `
export const createContributedRepoQuery = (username: string) => `
query {
user(login: "${username}") {
repositoriesContributedTo(last: 100) {
repositoriesContributedTo(last: 100, includeUserRepositories: true) {
nodes {
isFork
name
owner {
login
Expand Down

0 comments on commit b4425c9

Please sign in to comment.