Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alexleventer committed Sep 4, 2019
0 parents commit 6b06854
Show file tree
Hide file tree
Showing 10 changed files with 3,541 additions and 0 deletions.
95 changes: 95 additions & 0 deletions .gitignore
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/
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions action.yml
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'
11 changes: 11 additions & 0 deletions jest.config.js
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
};
20 changes: 20 additions & 0 deletions package.json
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"
}
}
46 changes: 46 additions & 0 deletions src/Octokit.ts
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});
}
});
}
}
27 changes: 27 additions & 0 deletions src/app.ts
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();
7 changes: 7 additions & 0 deletions src/utils/dateUtils.ts
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');
};
12 changes: 12 additions & 0 deletions tsconfig.json
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"]
}
Loading

0 comments on commit 6b06854

Please sign in to comment.