Skip to content

Commit

Permalink
feat: add lock pr
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Mar 8, 2019
1 parent 6149bf3 commit 8fe8016
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 196 deletions.
25 changes: 24 additions & 1 deletion lib/context/repoContext.js
Expand Up @@ -2,6 +2,7 @@

'use strict';

const Lock = require('lock').Lock;
const teamConfigs = require('../teamconfigs');
const { obtainTeamContext } = require('./teamContext');
const initRepoLabels = require('./initRepoLabels');
Expand Down Expand Up @@ -106,9 +107,31 @@ const initRepoContext = async (context, config) => {
}
};

const lock = Lock();

return Object.assign(repoContext, {
updateStatusCheckFromLabels,

lockPR: (context, callback) =>
new Promise((resolve, reject) => {
const pr = context.payload.pull_request;
console.log('try to lock pr', { id: pr.id });
lock(pr.id, async (release) => {
console.log('pr lock acquired', { id: pr.id });
try {
await callback();
} catch (err) {
console.log('release pr (with error)', { id: pr.id });
release()();
reject(err);
return;
}
console.log('release pr', { id: pr.id });
release()();
resolve();
});
}),

updateReviewStatus: async (
context,
reviewGroup,
Expand Down Expand Up @@ -153,7 +176,7 @@ const initRepoContext = async (context, config) => {
newLabels: [...newLabels],
});

if (process.env.DRY_RUN) return;
// if (process.env.DRY_RUN) return;

if (toAdd.size || toDelete.size) {
await context.github.issues.replaceLabels(
Expand Down

0 comments on commit 8fe8016

Please sign in to comment.