switched from GH-based CI to local bundling via zeit/ncc
This commit is contained in:
@@ -1,71 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const octokit_1 = __importDefault(require("./octokit"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const github_1 = require("@actions/github");
|
||||
function addEmptyCommit() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const contributorName = github_1.context.payload.comment.user.login;
|
||||
core.info(`Adding empty commit for ${contributorName} who has signed the CLA `);
|
||||
if (github_1.context.payload.comment) {
|
||||
//Do empty commit only when the contributor signs the CLA with the PR comment
|
||||
if (github_1.context.payload.comment.body === 'I have read the CLA Document and I hereby sign the CLA') {
|
||||
try {
|
||||
const message = ` @${contributorName} has signed the CLA `;
|
||||
const pullRequestResponse = yield octokit_1.default.pulls.get({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
pull_number: github_1.context.payload.issue.number
|
||||
});
|
||||
const baseCommit = yield octokit_1.default.git.getCommit({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
commit_sha: pullRequestResponse.data.head.sha
|
||||
});
|
||||
const tree = yield octokit_1.default.git.getTree({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
tree_sha: baseCommit.data.tree.sha
|
||||
});
|
||||
const newCommit = yield octokit_1.default.git.createCommit({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
message: message,
|
||||
tree: tree.data.sha,
|
||||
parents: [pullRequestResponse.data.head.sha]
|
||||
});
|
||||
return octokit_1.default.git.updateRef({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
ref: `heads/${pullRequestResponse.data.head.ref}`,
|
||||
sha: newCommit.data.sha
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
core.error(`failed when adding empty commit with the contributor's signature name `);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
});
|
||||
}
|
||||
exports.addEmptyCommit = addEmptyCommit;
|
||||
@@ -1,48 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fetch = require("node-fetch");
|
||||
const core = __importStar(require("@actions/core"));
|
||||
function blockChainWebhook(newSignedCommitters) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const blockchainURL = core.getInput('blockchain-webhook-endpoint') || 'https://u9afh6n36g.execute-api.eu-central-1.amazonaws.com/dev/webhook';
|
||||
try {
|
||||
const config = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(newSignedCommitters)
|
||||
};
|
||||
const res = yield fetch(blockchainURL, config);
|
||||
const response = yield res.json();
|
||||
core.debug("the response of the webhook is " + JSON.stringify(response));
|
||||
//const response = await res.json()
|
||||
if (response.success) {
|
||||
core.debug("the response2 of the webhook is " + JSON.stringify(response));
|
||||
//return json
|
||||
return response;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed('The webhook post request for storing signatures in smart contract failed' + error);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.default = blockChainWebhook;
|
||||
@@ -1,29 +0,0 @@
|
||||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const _ = require('lodash');
|
||||
const core = __importStar(require("@actions/core"));
|
||||
function isUserWhitelisted(committer) {
|
||||
const whitelistedItem = core.getInput("whitelist");
|
||||
const whitelistPatterns = whitelistedItem.split(',');
|
||||
return whitelistPatterns.filter(function (pattern) {
|
||||
pattern = pattern.trim();
|
||||
if (pattern.includes('*')) {
|
||||
const regex = _.escapeRegExp(pattern).split('\\*').join('.*');
|
||||
return new RegExp(regex).test(committer);
|
||||
}
|
||||
return pattern === committer;
|
||||
}).length > 0;
|
||||
}
|
||||
function checkWhitelist(committers) {
|
||||
const committersAfterWhiteListCheck = committers.filter(committer => committer && !(isUserWhitelisted !== undefined && isUserWhitelisted(committer.name)));
|
||||
console.debug("committersAfterWhiteListCheck " + JSON.stringify(committersAfterWhiteListCheck, null, 2));
|
||||
return committersAfterWhiteListCheck;
|
||||
}
|
||||
exports.checkWhitelist = checkWhitelist;
|
||||
-165
@@ -1,165 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const graphql_1 = __importDefault(require("./graphql"));
|
||||
const octokit_1 = __importDefault(require("./octokit"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const github_1 = require("@actions/github");
|
||||
const pullRequestComment_1 = __importDefault(require("./pullRequestComment"));
|
||||
const checkWhiteList_1 = require("./checkWhiteList");
|
||||
const _ = require('lodash');
|
||||
function prepareCommiterMap(committers, clas) {
|
||||
let committerMap = {};
|
||||
committerMap.notSigned = committers.filter(committer => !clas.signedContributors.some(cla => committer.id === cla.id));
|
||||
committerMap.signed = committers.filter(committer => clas.signedContributors.some(cla => committer.id === cla.id));
|
||||
committers.map(committer => {
|
||||
if (!committer.id) {
|
||||
committerMap.unknown.push(committer);
|
||||
}
|
||||
});
|
||||
return committerMap;
|
||||
}
|
||||
function updateFile(pathToClaSignatures, sha, contentBinary, branch, pullRequestNo) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield octokit_1.default.repos.createOrUpdateFile({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
path: pathToClaSignatures,
|
||||
sha: sha,
|
||||
message: `**CLA Assistant Action** Updating file for storing signatures from Pull Request ${pullRequestNo}`,
|
||||
content: contentBinary,
|
||||
branch: branch
|
||||
});
|
||||
});
|
||||
}
|
||||
function createFile(pathToClaSignatures, contentBinary, branch) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
/* TODO: add dynamic Message content */
|
||||
let response = yield octokit_1.default.repos.createOrUpdateFile({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
path: pathToClaSignatures,
|
||||
message: "**CLA Assistant Action** Creating file for storing CLA Signatures",
|
||||
content: contentBinary,
|
||||
branch: branch
|
||||
});
|
||||
return response;
|
||||
});
|
||||
}
|
||||
function getclas(pullRequestNo) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let committerMap = {};
|
||||
let signed = false;
|
||||
//getting the path of the cla from the user
|
||||
let pathToClaSignatures = core.getInput("path-to-signatures");
|
||||
let branch = core.getInput("branch");
|
||||
if (!pathToClaSignatures || pathToClaSignatures == "") {
|
||||
pathToClaSignatures = "signatures/cla.json"; // default path for storing the signatures
|
||||
}
|
||||
if (!branch || branch == "") {
|
||||
branch = "master";
|
||||
}
|
||||
let result, clas, sha;
|
||||
let committers = (yield graphql_1.default());
|
||||
//TODO code in more readable and efficient way
|
||||
committers = checkWhiteList_1.checkWhitelist(committers);
|
||||
try {
|
||||
result = yield octokit_1.default.repos.getContents({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
path: pathToClaSignatures,
|
||||
ref: branch
|
||||
});
|
||||
sha = result.data.sha;
|
||||
}
|
||||
catch (error) {
|
||||
if (error.status === 404) {
|
||||
committerMap.notSigned = committers;
|
||||
committerMap.signed = [];
|
||||
committers.map(committer => {
|
||||
if (!committer.id) {
|
||||
committerMap.unknown.push(committer);
|
||||
}
|
||||
});
|
||||
const initialContent = { signedContributors: [] };
|
||||
const initalContentString = JSON.stringify(initialContent, null, 2);
|
||||
const initalContentBinary = Buffer.from(initalContentString).toString("base64");
|
||||
const promise = Promise.all([createFile(pathToClaSignatures, initalContentBinary, branch), pullRequestComment_1.default(signed, committerMap, committers, pullRequestNo)]);
|
||||
if (promise) {
|
||||
core.setFailed(`committers of pull request ${github_1.context.issue.number} has to sign the CLA`);
|
||||
return;
|
||||
}
|
||||
core.setFailed("error occured when creating the signed contributors file " + error);
|
||||
}
|
||||
else {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
clas = Buffer.from(result.data.content, "base64").toString();
|
||||
clas = JSON.parse(clas);
|
||||
committerMap = prepareCommiterMap(committers, clas);
|
||||
core.debug("unsigned contributors are: " + JSON.stringify(committerMap.notSigned, null, 2));
|
||||
core.debug("signed contributors are: " + JSON.stringify(committerMap.signed, null, 2));
|
||||
//DO NULL CHECK FOR below
|
||||
if (committerMap) {
|
||||
if (committerMap.notSigned) {
|
||||
if (committerMap.notSigned.length === 0) {
|
||||
core.debug("null check");
|
||||
signed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
const reactedCommitters = (yield pullRequestComment_1.default(signed, committerMap, committers, pullRequestNo));
|
||||
if (signed) {
|
||||
core.info("All committers have signed the CLA");
|
||||
return;
|
||||
}
|
||||
if (reactedCommitters) {
|
||||
if (reactedCommitters.newSigned) {
|
||||
clas.signedContributors.push(...reactedCommitters.newSigned);
|
||||
let contentString = JSON.stringify(clas, null, 2);
|
||||
let contentBinary = Buffer.from(contentString).toString("base64");
|
||||
/* pushing the recently signed contributors to the CLA Json File */
|
||||
yield updateFile(pathToClaSignatures, sha, contentBinary, branch, pullRequestNo);
|
||||
}
|
||||
if (reactedCommitters.allSignedFlag) {
|
||||
core.info("All committers have signed the CLA");
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* return when there are no unsigned committers */
|
||||
if (committerMap.notSigned === undefined || committerMap.notSigned.length === 0) {
|
||||
core.info("All committers have signed the CLA");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
core.setFailed(`committers of Pull Request number ${github_1.context.issue.number} has to sign the CLA`);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
core.setFailed(err.message);
|
||||
throw new Error("error while updating the JSON file" + err);
|
||||
}
|
||||
return clas;
|
||||
});
|
||||
}
|
||||
exports.getclas = getclas;
|
||||
@@ -1,97 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const octokit_1 = __importDefault(require("./octokit"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const github_1 = require("@actions/github");
|
||||
function getCommitters() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
let committers = [];
|
||||
let filteredCommitters = [];
|
||||
let response = yield octokit_1.default.graphql(`
|
||||
query($owner:String! $name:String! $number:Int! $cursor:String!){
|
||||
repository(owner: $owner, name: $name) {
|
||||
pullRequest(number: $number) {
|
||||
commits(first: 100, after: $cursor) {
|
||||
totalCount
|
||||
edges {
|
||||
node {
|
||||
commit {
|
||||
author {
|
||||
email
|
||||
name
|
||||
user {
|
||||
id
|
||||
databaseId
|
||||
login
|
||||
}
|
||||
}
|
||||
committer {
|
||||
name
|
||||
user {
|
||||
id
|
||||
databaseId
|
||||
login
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cursor
|
||||
}
|
||||
pageInfo {
|
||||
endCursor
|
||||
hasNextPage
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`.replace(/ /g, ''), {
|
||||
owner: github_1.context.repo.owner,
|
||||
name: github_1.context.repo.repo,
|
||||
number: github_1.context.issue.number,
|
||||
cursor: ''
|
||||
});
|
||||
response.repository.pullRequest.commits.edges.forEach(edge => {
|
||||
let committer = extractUserFromCommit(edge.node.commit);
|
||||
let user = {
|
||||
name: committer.login || committer.name,
|
||||
id: committer.databaseId || '',
|
||||
pullRequestNo: github_1.context.issue.number
|
||||
};
|
||||
if (committers.length === 0 || committers.map((c) => {
|
||||
return c.name;
|
||||
}).indexOf(user.name) < 0) {
|
||||
committers.push(user);
|
||||
}
|
||||
});
|
||||
filteredCommitters = committers.filter((committer) => {
|
||||
return committer.id !== 41898282;
|
||||
});
|
||||
return filteredCommitters;
|
||||
}
|
||||
catch (e) {
|
||||
core.setFailed('graphql call to get the committers details failed:' + e);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.default = getCommitters;
|
||||
const extractUserFromCommit = (commit) => commit.author.user || commit.committer.user || commit.author || commit.committer;
|
||||
@@ -1,2 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
+1
-42
File diff suppressed because one or more lines are too long
-42
@@ -1,42 +0,0 @@
|
||||
"use strict";
|
||||
// const _ = require('lodash')
|
||||
// import * as core from "@actions/core"
|
||||
// function isUserWhitelisted(committer) {
|
||||
// const whitelistedItem: string = core.getInput("whitelist")
|
||||
// const whitelistPatterns: string[] = whitelistedItem.split(',')
|
||||
// //const whitelistPatterns = ['ibakshay', 'testuser61', 'bot*']
|
||||
// return whitelistPatterns.filter(function (pattern) {
|
||||
// pattern = pattern.trim()
|
||||
// if (pattern.includes('*')) {
|
||||
// const regex = _.escapeRegExp(pattern).split('\\*').join('.*')
|
||||
// return new RegExp(regex).test(committer)
|
||||
// }
|
||||
// console.log("whitelist pattern is " + pattern)
|
||||
// console.log("committer is " + committer)
|
||||
// return pattern === committer
|
||||
// }).length > 0
|
||||
// }
|
||||
// export function prepareCommiterMap() {
|
||||
// const committers = [
|
||||
// {
|
||||
// name: "ibakshay",
|
||||
// id: 33329946,
|
||||
// pullRequestNo: 284
|
||||
// },
|
||||
// {
|
||||
// name: "becky",
|
||||
// id: 33329946,
|
||||
// pullRequestNo: 284
|
||||
// },
|
||||
// {
|
||||
// name: "testuser",
|
||||
// id: 33329946,
|
||||
// pullRequestNo: 284
|
||||
// }
|
||||
// ]
|
||||
// //const committersAfterWhiteListCheck = committers.filter(committer => { isUserWhitelisted(committer.name) })
|
||||
// const committersAfterWhiteListCheck = committers.filter(committer => committer && !(isUserWhitelisted !== undefined && isUserWhitelisted(committer.name)))
|
||||
// // committer && !(isUserWhitelisted !== undefined && isUserWhitelisted(committer.name)))
|
||||
// console.log("committersAfterWhiteListCheck " + JSON.stringify(committersAfterWhiteListCheck, null, 2))
|
||||
// return committersAfterWhiteListCheck
|
||||
// }
|
||||
@@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const github_1 = require("@actions/github");
|
||||
const octokit = new github_1.GitHub(process.env.GITHUB_TOKEN);
|
||||
exports.default = octokit;
|
||||
@@ -1,184 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const octokit_1 = __importDefault(require("./octokit"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const url_1 = require("./url");
|
||||
const github_1 = require("@actions/github");
|
||||
const signatureComment_1 = __importDefault(require("./signatureComment"));
|
||||
function getComment() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const response = yield octokit_1.default.issues.listComments({ owner: github_1.context.repo.owner, repo: github_1.context.repo.repo, issue_number: github_1.context.issue.number });
|
||||
//TODO: check the below regex
|
||||
return response.data.find(comment => comment.body.match(/.*CLA Assistant Lite.*/));
|
||||
}
|
||||
catch (e) {
|
||||
core.setFailed("Error occured when getting all the comments of the pull request: " + e.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
function commentContent(signed, committerMap) {
|
||||
// const labelName = {} as LabelName;
|
||||
if (signed) {
|
||||
core.debug("all signed flag inside commentContent is" + signed);
|
||||
// labelName.current_name = "CLA signed :smiley:";
|
||||
// updateLabel(signed, labelName);
|
||||
return `**CLA Assistant Lite** All Contributors have signed the CLA. `;
|
||||
}
|
||||
//labelName.current_name = "CLA Not Signed :worried:";
|
||||
// updateLabel(signed, labelName)
|
||||
let committersCount = 1;
|
||||
if (committerMap && committerMap.signed && committerMap.notSigned) {
|
||||
committersCount =
|
||||
committerMap.signed.length + committerMap.notSigned.length;
|
||||
}
|
||||
let you = committersCount > 1 ? "you all" : "you";
|
||||
let text = `**CLA Assistant Lite:** <br/>Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that ${you} sign our [Contributor License Agreement](${url_1.pathToCLADocument()}) before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.
|
||||
- - -
|
||||
***I have read the CLA Document and I hereby sign the CLA***
|
||||
- - -
|
||||
`;
|
||||
if (committersCount > 1 && committerMap && committerMap.signed && committerMap.notSigned) {
|
||||
text += `**${committerMap.signed.length}** out of **${committerMap.signed.length + committerMap.notSigned.length}** committers have signed the CLA.`;
|
||||
committerMap.signed.forEach(signedCommitter => { text += `<br/>:white_check_mark: @${signedCommitter.name}`; });
|
||||
committerMap.notSigned.forEach(unsignedCommitter => {
|
||||
text += `<br/>:x: @${unsignedCommitter.name}`;
|
||||
});
|
||||
text += "<br/>";
|
||||
}
|
||||
if (committerMap && committerMap.unknown && committerMap.unknown.length > 0) {
|
||||
let seem = committerMap.unknown.length > 1 ? "seem" : "seems";
|
||||
text += `<hr/>**${committerMap.unknown.join(", ")}** ${seem} not to be a GitHub user.`;
|
||||
text += " You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please [add the email address used for this commit to your account](https://help.github.com/articles/why-are-my-commits-linked-to-the-wrong-user/#commits-are-not-linked-to-any-user).<br/>";
|
||||
}
|
||||
text += `<sub>You can retrigger the CLA Action by commenting **recheckcla** in this Pull Request</sub>`;
|
||||
return text;
|
||||
}
|
||||
function prepareAllSignedCommitters(committerMap, signedInPrCommitters, committers) {
|
||||
let allSignedCommitters = [];
|
||||
/*
|
||||
Reference: https://stackoverflow.com/questions/54134156/javascript-merge-two-arrays-of-objects-only-if-not-duplicate-based-on-specifi
|
||||
merging two arrays if not duplicate. 1) already signed committers in the file 2) signed committers in the PR comment
|
||||
*/
|
||||
let ids = new Set(signedInPrCommitters.map(committer => committer.id));
|
||||
allSignedCommitters = [...signedInPrCommitters, ...committerMap.signed.filter(signedCommitter => !ids.has(signedCommitter.id))];
|
||||
core.debug("all signed committers after merging " + JSON.stringify(allSignedCommitters, null, 2));
|
||||
//checking if all the unsigned committers have reacted to the PR comment (this is needed for changing the content of the PR comment to "All committers have signed the CLA")
|
||||
let allSignedFlag = committers.every(committer => allSignedCommitters.some(reactedCommitter => committer.id === reactedCommitter.id));
|
||||
return allSignedFlag;
|
||||
}
|
||||
function prComment(signed, committerMap, committers, pullRequestNo) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const prComment = yield getComment();
|
||||
if (!prComment) {
|
||||
yield octokit_1.default.issues.createComment({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
issue_number: github_1.context.issue.number,
|
||||
body: commentContent(signed, committerMap)
|
||||
});
|
||||
return;
|
||||
}
|
||||
else if (prComment && prComment.id) {
|
||||
if (signed) {
|
||||
yield octokit_1.default.issues.updateComment({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
comment_id: prComment.id,
|
||||
body: commentContent(signed, committerMap)
|
||||
});
|
||||
}
|
||||
const reactedCommitters = (yield signatureComment_1.default(prComment.id, committerMap, committers, pullRequestNo));
|
||||
if (reactedCommitters) {
|
||||
if (reactedCommitters.onlyCommitters) {
|
||||
reactedCommitters.allSignedFlag = prepareAllSignedCommitters(committerMap, reactedCommitters.onlyCommitters, committers);
|
||||
}
|
||||
}
|
||||
core.debug("allSignedFlag is " + reactedCommitters.allSignedFlag);
|
||||
committerMap.signed.push(...reactedCommitters.newSigned);
|
||||
committerMap.notSigned = committerMap.notSigned.filter(committer => !reactedCommitters.newSigned.some(reactedCommitter => committer.id === reactedCommitter.id));
|
||||
yield octokit_1.default.issues.updateComment({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
comment_id: prComment.id,
|
||||
body: commentContent(reactedCommitters.allSignedFlag, committerMap)
|
||||
});
|
||||
return reactedCommitters;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
core.setFailed("Error occured when creating or editing the comments of the pull request: " +
|
||||
e.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.default = prComment;
|
||||
// function addLabel() {
|
||||
// core.debug("updateLabel catch function");
|
||||
// return octokit.issues.addLabels({
|
||||
// owner: context.repo.owner,
|
||||
// repo: context.repo.repo,
|
||||
// issue_number: context.issue.number,
|
||||
// labels: ["CLA Signed"]
|
||||
// });
|
||||
// }
|
||||
// async function updateLabel(signed: boolean, labelName: LabelName) {
|
||||
// try {
|
||||
// core.debug("updateLabel function");
|
||||
// const getLabel = await octokit.issues.getLabel({
|
||||
// owner: context.repo.owner,
|
||||
// repo: context.repo.repo,
|
||||
// name: labelName.current_name
|
||||
// });
|
||||
// console.log(getLabel, null, 2);
|
||||
// if (getLabel) {
|
||||
// await addLabel();
|
||||
// return;
|
||||
// }
|
||||
// await addLabel();
|
||||
// } catch (error) {
|
||||
// if (error.status === 404) {
|
||||
// core.debug("updateLabel catch function");
|
||||
// await addLabel();
|
||||
// // if (signed) {
|
||||
// // labelName = {
|
||||
// // current_name: "CLA Not Signed",
|
||||
// // name: "CLA signed"
|
||||
// // };
|
||||
// // } else {
|
||||
// // labelName = {
|
||||
// // current_name: "CLA signed :smiley:",
|
||||
// // name: "CLA Not Signed :worried:"
|
||||
// // };
|
||||
// // }
|
||||
// // return octokit.issues.updateLabel({
|
||||
// // owner: context.repo.owner,
|
||||
// // repo: context.repo.repo,
|
||||
// // current_name: labelName.current_name,
|
||||
// // name: labelName.name
|
||||
// // });
|
||||
// // }
|
||||
// core.setFailed("error when creating a label :" + error);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@@ -1,41 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const octokit_1 = __importDefault(require("./octokit"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const github_1 = require("@actions/github");
|
||||
function lockPullRequest(pullRequestNo) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.info('Locking the Pull Request to safe guard the Pull Request CLA Signatures');
|
||||
try {
|
||||
yield octokit_1.default.issues.lock({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
issue_number: pullRequestNo
|
||||
});
|
||||
core.info(`successfully locked the pull request ${pullRequestNo}`);
|
||||
}
|
||||
catch (e) {
|
||||
core.error(`failed when locking the pull request `);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.lockPullRequest = lockPullRequest;
|
||||
@@ -1,82 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const octokit_1 = __importDefault(require("./octokit"));
|
||||
const github_1 = require("@actions/github");
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const addEmptyCommit_1 = require("./addEmptyCommit");
|
||||
const blockChainWebhook_1 = __importDefault(require("./blockChainWebhook"));
|
||||
function signatureWithPRComment(commentId, committerMap, committers, pullRequestNo) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const blockchainFlag = core.getInput('blockchain-storage-flag');
|
||||
const emptyCommitFlag = core.getInput('empty-commit-flag');
|
||||
let repoId = github_1.context.payload.repository.id;
|
||||
let commentedCommitterMap = {};
|
||||
let prResponse = yield octokit_1.default.issues.listComments({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
issue_number: github_1.context.issue.number
|
||||
});
|
||||
let listOfPRComments = [];
|
||||
let filteredListOfPRComments = [];
|
||||
//TODO: Do null check for repoID
|
||||
prResponse.data.map((prComment) => {
|
||||
listOfPRComments.push({
|
||||
name: prComment.user.login,
|
||||
id: prComment.user.id,
|
||||
comment_id: prComment.id,
|
||||
body: prComment.body.toLowerCase(),
|
||||
created_at: prComment.created_at,
|
||||
repoId: repoId,
|
||||
pullRequestNo: pullRequestNo
|
||||
});
|
||||
});
|
||||
listOfPRComments.map((comment) => {
|
||||
if (comment.body.match(/^.*i \s*have \s*read \s*the \s*cla \s*document \s*and \s*i \s*hereby \s*sign \s*the \s*cla.*$/) && comment.name !== 'github-actions[bot]') {
|
||||
filteredListOfPRComments.push(comment);
|
||||
}
|
||||
});
|
||||
for (var i = 0; i < filteredListOfPRComments.length; i++) {
|
||||
delete filteredListOfPRComments[i].body;
|
||||
}
|
||||
// //checking if the reacted committers are not the signed committers(not in the storage file) and filtering only the unsigned committers
|
||||
commentedCommitterMap.newSigned = filteredListOfPRComments.filter(commentedCommitter => committerMap.notSigned.some(notSignedCommitter => commentedCommitter.id === notSignedCommitter.id));
|
||||
if (github_1.context.eventName === "issue_comment") {
|
||||
//Do empty commit only when the contributor signs the CLA with the PR comment and then check if the comment is from the newsigned contributor
|
||||
if (emptyCommitFlag == 'true') {
|
||||
core.debug(JSON.stringify(github_1.context.payload.comment.user.id));
|
||||
if (commentedCommitterMap.newSigned.some(contributor => contributor.id === github_1.context.payload.comment.user.id)) {
|
||||
core.debug("Adding empty commit for the signee");
|
||||
yield addEmptyCommit_1.addEmptyCommit();
|
||||
}
|
||||
}
|
||||
}
|
||||
core.debug("the new commented committers(signed) are :" + JSON.stringify(commentedCommitterMap.newSigned, null, 3));
|
||||
if (blockchainFlag == 'true' && commentedCommitterMap.newSigned) {
|
||||
yield blockChainWebhook_1.default(commentedCommitterMap.newSigned);
|
||||
}
|
||||
//checking if the commented users are only the contributors who has committed in the same PR (This is needed for the PR Comment and changing the status to success when all the contributors has reacted to the PR)
|
||||
commentedCommitterMap.onlyCommitters = committers.filter(committer => filteredListOfPRComments.some(commentedCommitter => committer.id == commentedCommitter.id));
|
||||
core.debug("the reacted signed committers comments are " + JSON.stringify(commentedCommitterMap.onlyCommitters, null, 3));
|
||||
return commentedCommitterMap;
|
||||
});
|
||||
}
|
||||
exports.default = signatureWithPRComment;
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
function pathToCLADocument() {
|
||||
const pathToCLADocument = core.getInput('path-To-cladocument');
|
||||
return pathToCLADocument;
|
||||
}
|
||||
exports.pathToCLADocument = pathToCLADocument;
|
||||
Generated
+6
@@ -644,6 +644,12 @@
|
||||
"integrity": "sha512-gCubfBUZ6KxzoibJ+SCUc/57Ms1jz5NjHe4+dI2krNmU5zCPAphyLJYyTOg06ueIyfj+SaCUqmzun7ImlxDcKg==",
|
||||
"dev": true
|
||||
},
|
||||
"@zeit/ncc": {
|
||||
"version": "0.21.1",
|
||||
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.21.1.tgz",
|
||||
"integrity": "sha512-M9WzgquSOt2nsjRkYM9LRylBLmmlwNCwYbm3Up3PDEshfvdmIfqpFNSK8EJvR18NwZjGHE5z2avlDtYQx2JQnw==",
|
||||
"dev": true
|
||||
},
|
||||
"abab": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/abab/-/abab-2.0.3.tgz",
|
||||
|
||||
+2
-1
@@ -5,7 +5,7 @@
|
||||
"main": "lib/main.js",
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"build": "tsc"
|
||||
"build": "ncc build ./src/main.ts -o ./lib -m && mv ./lib/index.js ./lib/main.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -28,6 +28,7 @@
|
||||
"devDependencies": {
|
||||
"@types/jest": "^24.0.13",
|
||||
"@types/node": "^12.0.4",
|
||||
"@zeit/ncc": "^0.21.1",
|
||||
"jest": "^24.8.0",
|
||||
"jest-circus": "^24.7.1",
|
||||
"ts-jest": "^24.2.0",
|
||||
|
||||
Reference in New Issue
Block a user