Skip to content

Commit

Permalink
add pull request check, fixes: #42
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamkrishnar committed May 24, 2024
1 parent 5a25dc7 commit 630defc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions library.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const { Octokit } = require("@octokit/rest");
const KeepAliveWorkflow = async (githubToken, committerUsername, committerEmail, commitMessage, timeElapsed = 50, autoPush = false, autoWriteCheck = false) => {
return new Promise(async (resolve, reject) => {
try {
writeDetectionCheck(autoWriteCheck, reject);
writeDetectionCheck(autoWriteCheck, reject, resolve);
const diffInDays = await getDiffInDays();
if (diffInDays >= timeElapsed) {
// Do dummy commit if elapsed time is greater than 50 (default) days
Expand Down Expand Up @@ -93,7 +93,7 @@ const APIKeepAliveWorkflow = (githubToken,
} = {}) => {
return new Promise(async (resolve, reject) => {
try {
writeDetectionCheck(autoWriteCheck, reject);
writeDetectionCheck(autoWriteCheck, reject, resolve);
const diffInDays = await getDiffInDays();
if (diffInDays >= timeElapsed) {
const octokit = new Octokit({
Expand Down
11 changes: 8 additions & 3 deletions util.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,18 @@ const getDiffInDays = async () => {
/**
* Automatic write check
* @param {boolean} autoWriteCheck
* @param {function(string): void} cb callback on check failure
* @param {function(string): void} cbReject failure callback
* @param {function(string): void} cbResolve success callback
*/
const writeDetectionCheck = (autoWriteCheck, cb) => {
const writeDetectionCheck = (autoWriteCheck, cbReject, cbResolve) => {
if (autoWriteCheck) {
// Protected branches
if (process.env.GITHUB_REF_PROTECTED === 'true') {
cb(`Looks like the branch is write protected. You need to disable that for this to work: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches`)
cbReject(`Looks like the branch is write protected. You need to disable that for this to work: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches`)
}
// Pull request check - Do nothing
if (process.env.GITHUB_EVENT_NAME === 'pull_request' || process.env.GITHUB_EVENT_NAME === 'pull_request_target') {
cbResolve('Looks like this is triggered via a pull request. Doing Nothing...');
}
}
}
Expand Down

0 comments on commit 630defc

Please sign in to comment.