Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Slack from "./src/services/Slack.js";
import {
getMessage,
isCLARequired,
getCLASignature,
isMessageAfterMergeRequired,
getWebsiteAddress,
} from "./src/helpers.js";
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 17 additions & 5 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down