Created
April 30, 2020 08:02
-
-
Save pezholio/fea31bd49cec00b97ef8e629e5ef7cdb to your computer and use it in GitHub Desktop.
PR age checker
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
const { Octokit } = require("@octokit/rest"); | |
const octokit = new Octokit({ | |
auth: process.env.GITHUB_TOKEN, | |
}) | |
const repoOwner = process.env.REPOSITORY_OWNER; | |
const repoName = process.env.REPOSITORY_NAME; | |
var getOpenPRs = function() { | |
return octokit.pulls.list({ | |
owner: repoOwner, | |
repo: repoName, | |
state: "open" | |
}) | |
} | |
var createCheck = function(sha, state, description) { | |
return octokit.repos.createStatus({ | |
owner: repoOwner, | |
repo: repoName, | |
sha: sha, | |
state: state, | |
description: description, | |
context: "PR age checker" | |
}) | |
} | |
getOpenPRs().then(function(response) { | |
var today = new Date() | |
var twoWeeksAgo = new Date(today - 1209600000) | |
response.data.forEach(function(pr) { | |
if (new Date(pr.created_at) > twoWeeksAgo) { | |
// Create a pending check | |
createCheck(pr.head.sha, "pending", "This PR is less than two weeks old"); | |
} else { | |
// Create a passing check | |
createCheck(pr.head.sha, "success", "This PR is old enough to be merged"); | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment