diff --git a/app.js b/app.js index 7ffacde..2bd1b41 100644 --- a/app.js +++ b/app.js @@ -10,6 +10,7 @@ import Slack from "./src/services/Slack.js"; import { getMessage, isCLARequired, + getCLASignature, isMessageAfterMergeRequired, getWebsiteAddress, } from "./src/helpers.js"; @@ -67,7 +68,19 @@ GitHub.app.webhooks.on("pull_request.opened", async ({ octokit, payload }) => { console.log("CLA not required for this PR"); return; } - // If the user is not a member of the organization and haven't yet signed CLA, + // CLA is required for this PR, check if the user has already signed the CLA + const claSignature = getCLASignature(payload.pull_request.user.login); + if(claSignature) { + console.log("CLA already signed by this user"); + octokit.rest.issues.addLabels({ + owner: payload.repository.owner.login, + repo: payload.repository.name, + issue_number: payload.pull_request.number, + labels: ["CLA Signed"], + }); + return; + } + // The user is not a member of the organization and haven't yet signed CLA, // Add a label to the PR octokit.rest.issues.addLabels({ owner: payload.repository.owner.login, diff --git a/src/helpers.js b/src/helpers.js index 515b500..5a47878 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -53,8 +53,16 @@ export function isCLARequired(pullRequest) { console.log("This PR is an internal contribution. So no CLA required."); return false; } + return true; +} + +export function isCLAPending(pullRequest) { + if (!isCLARequired(pullRequest)) { + console.log("CLA is not required for this PR. So no CLA pending."); + return false; + } if (isCLASigned(pullRequest.user.login)) { - console.log("Author signed CLA already. So no CLA required."); + console.log("Author signed CLA already. So no CLA pending."); return false; } return true; @@ -262,11 +270,15 @@ export function getMessage(name, context) { export function isCLASigned(username) { if (!username) return; + const claSignature = getCLASignature(username); + return claSignature ? true : false; +} + +export function getCLASignature(username) { + if (!username) return; + //TODO: Ensure the data is sorted by serverTimestamp in descending order const userData = storage.get({ username: username, terms: "on" }); - if (userData?.length > 0) { - return true; - } - return false; + return userData?.length > 0 ? userData[0] : null; } export function jsonToCSV(arr) {