forked from alexleventer/github-issue-due-dates-action
-
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.
- Loading branch information
0 parents
commit 6b06854
Showing
10 changed files
with
3,541 additions
and
0 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,95 @@ | ||
__tests__/runner/* | ||
|
||
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# next.js build output | ||
.next | ||
|
||
# nuxt.js build output | ||
.nuxt | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
dist/ | ||
|
||
.idea/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: ' GitHub Issue Due Dates Action' | ||
description: 'Add overdue labels to past-due GitHub issues' | ||
author: 'Alex Leventer' | ||
inputs: | ||
GITHUB_TOKEN: | ||
description: GitHub token used to make API requests | ||
required: true | ||
runs: | ||
using: 'node12' | ||
main: 'dist/app.js' |
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,11 @@ | ||
module.exports = { | ||
clearMocks: true, | ||
moduleFileExtensions: ['js', 'ts'], | ||
testEnvironment: 'node', | ||
testMatch: ['**/*.test.ts'], | ||
testRunner: 'jest-circus/runner', | ||
transform: { | ||
'^.+\\.ts$': 'ts-jest' | ||
}, | ||
verbose: 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,20 @@ | ||
{ | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "jest" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^24.0.18", | ||
"@types/moment": "^2.13.0", | ||
"jest": "^24.9.0", | ||
"jest-circus": "^24.9.0", | ||
"ts-jest": "^24.0.2", | ||
"typescript": "^3.6.2" | ||
}, | ||
"dependencies": { | ||
"@actions/core": "^1.0.0", | ||
"@actions/github": "^1.0.1", | ||
"front-matter": "^3.0.2", | ||
"moment": "^2.24.0" | ||
} | ||
} |
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,46 @@ | ||
import {GitHub, context} from '@actions/github'; | ||
import fm from 'front-matter'; | ||
|
||
export default class Octokit { | ||
public client: GitHub; | ||
|
||
constructor(token: string) { | ||
this.client = new GitHub(token); | ||
} | ||
|
||
async listAllOpenIssues(owner: string, repo: string) { | ||
const {data} = await this.client.issues.listForRepo({ | ||
owner, | ||
repo, | ||
state: 'open', | ||
}); | ||
return data; | ||
} | ||
|
||
async addLabelToIssue(owner: string, repo: string, issueNumber: number, labels: string[]) { | ||
return await this.client.issues.addLabels({ | ||
owner, | ||
repo, | ||
issue_number: issueNumber, | ||
labels, | ||
}) | ||
} | ||
|
||
async removeLabelFromIssue(owner: string, repo: string, name: string, issue_number: number) { | ||
return await this.client.issues.removeLabel({ | ||
owner, | ||
repo, | ||
name, | ||
issue_number, | ||
}); | ||
} | ||
|
||
async getIssuesWithDueDate(rawIssues: any[]) { | ||
return rawIssues.filter(issue => { | ||
const meta: any = fm(issue.body); | ||
if (meta.attributes && meta.attributes.due) { | ||
return Object.assign(issue, {due: meta.attributes.due}); | ||
} | ||
}); | ||
} | ||
} |
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,27 @@ | ||
import * as core from '@actions/core'; | ||
import {GitHub, context} from '@actions/github'; | ||
import Octokit from './Octokit'; | ||
import {datesToDue} from './utils/dateUtils'; | ||
|
||
const run = async () => { | ||
try { | ||
const githubToken = core.getInput('GITHUB_TOKEN'); | ||
const ok = new Octokit(githubToken); | ||
|
||
const issues = await ok.listAllOpenIssues(context.repo.owner, context.repo.repo); | ||
const results = await ok.getIssuesWithDueDate(issues); | ||
results.forEach(async issue => { | ||
const daysUtilDueDate = await datesToDue(issue.due); | ||
if (daysUtilDueDate <= 7 && daysUtilDueDate > 0) { | ||
await ok.addLabelToIssue(context.repo.owner, context.repo.repo, issue.number, ['Due in next week']); | ||
} else if (daysUtilDueDate <= 0) { | ||
await ok.removeLabelFromIssue(context.repo.owner, context.repo.repo, 'Due in next week', issue.number); | ||
await ok.addLabelToIssue(context.repo.owner, context.repo.repo, issue.number, ['Overdue']); | ||
} | ||
}); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
}; | ||
|
||
run(); |
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,7 @@ | ||
import moment from 'moment'; | ||
|
||
export const datesToDue = (date: string) => { | ||
const eventDate = moment(date); | ||
const today = moment(); | ||
return eventDate.diff(today, 'days'); | ||
}; |
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,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"module": "commonjs", | ||
"outDir": "./dist", | ||
"rootDir": "./src", | ||
"strict": true, | ||
"noImplicitAny": false, | ||
"esModuleInterop": true, | ||
}, | ||
"exclude": ["node_modules", "**/*.test.ts"] | ||
} |
Oops, something went wrong.