-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const core = __importStar(require("@actions/core")); | ||
const github_1 = require("@actions/github"); | ||
const Octokit_1 = __importDefault(require("./integrations/Octokit")); | ||
const dateUtils_1 = require("./utils/dateUtils"); | ||
const constants_1 = require("./constants"); | ||
exports.run = () => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const githubToken = core.getInput('GH_TOKEN'); | ||
if (!githubToken) { | ||
throw new Error('Missing GH_TOKEN environment variable'); | ||
} | ||
const ok = new Octokit_1.default(githubToken); | ||
const issues = yield ok.listAllOpenIssues(github_1.context.repo.owner, github_1.context.repo.repo); | ||
const results = yield ok.getIssuesWithDueDate(issues); | ||
results.forEach((issue) => __awaiter(void 0, void 0, void 0, function* () { | ||
const daysUtilDueDate = yield dateUtils_1.datesToDue(issue.due); | ||
if (daysUtilDueDate <= 7 && daysUtilDueDate > 0) { | ||
yield ok.addLabelToIssue(github_1.context.repo.owner, github_1.context.repo.repo, issue.number, [constants_1.NEXT_WEEK_TAG_NAME]); | ||
} | ||
else if (daysUtilDueDate <= 0) { | ||
yield ok.removeLabelFromIssue(github_1.context.repo.owner, github_1.context.repo.repo, constants_1.NEXT_WEEK_TAG_NAME, issue.number); | ||
yield ok.addLabelToIssue(github_1.context.repo.owner, github_1.context.repo.repo, issue.number, [constants_1.OVERDUE_TAG_NAME]); | ||
} | ||
})); | ||
return { | ||
ok: true, | ||
issuesProcessed: results.length, | ||
}; | ||
} | ||
catch (e) { | ||
core.setFailed(e.message); | ||
throw e; | ||
} | ||
}); | ||
exports.run(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OVERDUE_TAG_NAME = 'Overdue'; | ||
exports.NEXT_WEEK_TAG_NAME = 'Due in next week'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const github_1 = require("@actions/github"); | ||
const front_matter_1 = __importDefault(require("front-matter")); | ||
const constants_1 = require("../constants"); | ||
class Octokit { | ||
constructor(token) { | ||
this.client = new github_1.GitHub(token); | ||
} | ||
listAllOpenIssues(owner, repo) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { data } = yield this.client.issues.listForRepo({ | ||
owner, | ||
repo, | ||
state: 'open', | ||
}); | ||
return data; | ||
}); | ||
} | ||
get(owner, repo, issueNumber) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { data } = yield this.client.issues.get({ | ||
owner, | ||
repo, | ||
issue_number: issueNumber, | ||
}); | ||
return data; | ||
}); | ||
} | ||
addLabelToIssue(owner, repo, issueNumber, labels) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { data } = yield this.client.issues.addLabels({ | ||
owner, | ||
repo, | ||
issue_number: issueNumber, | ||
labels, | ||
}); | ||
return data; | ||
}); | ||
} | ||
removeLabelFromIssue(owner, repo, name, issue_number) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const { data } = yield this.client.issues.removeLabel({ | ||
owner, | ||
repo, | ||
name, | ||
issue_number, | ||
}); | ||
return data; | ||
} | ||
catch (e) { | ||
// Do not throw error | ||
return []; | ||
} | ||
}); | ||
} | ||
getIssuesWithDueDate(rawIssues) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return rawIssues.filter(issue => { | ||
// TODO: Move into utils | ||
const meta = front_matter_1.default(issue.body); | ||
const due = meta.attributes && (meta.attributes.due || meta.attributes.Due); | ||
if (meta.attributes && due) { | ||
return Object.assign(issue, { due }); | ||
} | ||
}); | ||
}); | ||
} | ||
getOverdueIssues(rawIssues) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return rawIssues.filter(issue => { | ||
const activeLabels = issue.labels.map(label => label.name); | ||
return activeLabels.includes(constants_1.OVERDUE_TAG_NAME); | ||
}); | ||
}); | ||
} | ||
} | ||
exports.default = Octokit; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const client_1 = require("@slack/client"); | ||
class Slack { | ||
constructor(webhookUrl) { | ||
this.webhook = new client_1.IncomingWebhook(webhookUrl); | ||
} | ||
postMessage(message) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.webhook.send(message); | ||
}); | ||
} | ||
} | ||
exports.default = Slack; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const moment_1 = __importDefault(require("moment")); | ||
exports.datesToDue = (date) => { | ||
const eventDate = moment_1.default(date); | ||
const today = moment_1.default(); | ||
return eventDate.diff(today, 'days'); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.