mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-9462] Being able to add contributors of the current upstream (#7705)
* Being able to add contributors of the current upstream * Fix typo * Fix comments
This commit is contained in:
@@ -161,7 +161,7 @@ jobs:
|
|||||||
|
|
||||||
- stage: "Trigger Alpha ADF child build"
|
- stage: "Trigger Alpha ADF child build"
|
||||||
name: "Trigger Alpha ADF child build"
|
name: "Trigger Alpha ADF child build"
|
||||||
script: ./scripts/travis/update/update-project.sh -p $TRAVIS_BUILD_NUMBER -t $GITHUB_TOKEN -v alpha
|
script: ./scripts/travis/update/update-project.sh -p $TRAVIS_BUILD_NUMBER -t $GITHUB_TOKEN -v alpha -c $TRAVIS_COMMIT
|
||||||
workspaces:
|
workspaces:
|
||||||
use: built_libs_cache
|
use: built_libs_cache
|
||||||
|
|
||||||
|
@@ -2,25 +2,94 @@ const GitHub = require('github-api');
|
|||||||
let program = require('commander');
|
let program = require('commander');
|
||||||
|
|
||||||
const ORGANISATION = 'Alfresco';
|
const ORGANISATION = 'Alfresco';
|
||||||
|
const ORIGIN_REPO = 'alfresco-ng2-components';
|
||||||
|
const ATTEMPT_MSG = [
|
||||||
|
`Could you check it please? 🤖`,
|
||||||
|
`Emm did you forget? 🤡`,
|
||||||
|
`Where are you? 🤷`,
|
||||||
|
`We are going to die!! 👻`,
|
||||||
|
`I guess the Apocalypse happened and I am alone 👽`
|
||||||
|
];
|
||||||
|
|
||||||
|
GIVE_UP_MSG = `I gave up, it will be fix eventually 🔴`;
|
||||||
|
|
||||||
class PrCreator {
|
class PrCreator {
|
||||||
constructor(githubUser, githubRepo, token) {
|
constructor(githubUser, githubRepo, token, commit) {
|
||||||
this.github = new GitHub({token});
|
this.github = new GitHub({token});
|
||||||
this.repo = this.github.getRepo(githubUser, githubRepo);
|
this.repoOrigin = this.github.getRepo(githubUser, ORIGIN_REPO);
|
||||||
|
this.repoDestination = this.github.getRepo(githubUser, githubRepo);
|
||||||
|
this.issue = this.github.getIssues(githubUser, githubRepo);
|
||||||
|
this.commit = commit;
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(title, head, base) {
|
async createOrUpdate(title, head, base, commit) {
|
||||||
const { data: prs } = await this.repo.listPullRequests({ state: 'open', head: `${ORGANISATION}:${head}`, base });
|
const { data: prs } = await this.repoDestination.listPullRequests({ state: 'open', head: `${ORGANISATION}:${head}`, base });
|
||||||
|
|
||||||
if (prs.length < 1) {
|
if (prs.length < 1) {
|
||||||
const { data: pr } = await this.repo.createPullRequest({ title, head, base });
|
const { data: pr } = await this.repoDestination.createPullRequest({ title, head, base, body: `sha:${commit}` });
|
||||||
return pr.number;
|
return pr.number;
|
||||||
} else {
|
} else {
|
||||||
|
const upstreamPrOpen = prs[0];
|
||||||
// override the title to contains the latest adf dep number
|
// override the title to contains the latest adf dep number
|
||||||
prs[0].title = title;
|
await this.repoDestination.updatePullRequest(upstreamPrOpen.number, { title, body: `sha:${commit}` });
|
||||||
|
return upstreamPrOpen.number;
|
||||||
}
|
}
|
||||||
|
|
||||||
return prs[0].number;
|
}
|
||||||
|
|
||||||
|
async fetchContributors(shaFrom, shaTo) {
|
||||||
|
const mapAuthors = new Map();
|
||||||
|
let upstreamShaFound = true;
|
||||||
|
const listCommits = await this.repoOrigin.listCommits(({sha: shaFrom}))
|
||||||
|
let index = 0;
|
||||||
|
while(upstreamShaFound) {
|
||||||
|
if (listCommits.data[index].sha === shaTo ) {
|
||||||
|
upstreamShaFound = false;
|
||||||
|
} else {
|
||||||
|
mapAuthors.set(listCommits.data[index].author.login, listCommits.data[index].commit.author.name);
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return mapAuthors;
|
||||||
|
}
|
||||||
|
|
||||||
|
async createComment(issueOrPrNumber, head, base, shaOriginHead ) {
|
||||||
|
const shaTo = await this.getShaTo(head, base);
|
||||||
|
const contributors = await this.fetchContributors(shaOriginHead, shaTo);
|
||||||
|
const attemptCount = await this.getCommentAmount(issueOrPrNumber);
|
||||||
|
const commentMsg = this.createCommentBody(contributors, attemptCount);
|
||||||
|
await this.issue.createIssueComment(issueOrPrNumber, commentMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
createCommentBody(contributors, attemptCount) {
|
||||||
|
const flattenedContributors = this.flattenContributors(contributors);
|
||||||
|
const attemptMsg = attemptCount <= 5 ? ATTEMPT_MSG[attemptCount] : GIVE_UP_MSG
|
||||||
|
const tmpl = ` Attempt: ${attemptCount+1}
|
||||||
|
you are part of the contributors:
|
||||||
|
${flattenedContributors}
|
||||||
|
${attemptMsg}
|
||||||
|
`;
|
||||||
|
return tmpl;
|
||||||
|
}
|
||||||
|
|
||||||
|
flattenContributors(contributors) {
|
||||||
|
let names = [];
|
||||||
|
for (let key of contributors.keys()) {
|
||||||
|
names.push(`@${key}`)
|
||||||
|
}
|
||||||
|
return names.join(', ');
|
||||||
|
}
|
||||||
|
|
||||||
|
async getShaTo(head, base) {
|
||||||
|
const { data: closedUpstreamPRs } = await this.repoDestination.listPullRequests({ state: 'closed', head: `${ORGANISATION}:${head}`, base });
|
||||||
|
const latestClosedUpstream = closedUpstreamPRs[0];
|
||||||
|
const shaTo = latestClosedUpstream.body.split(':')[1].trim();
|
||||||
|
return shaTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getCommentAmount(issueOrPrNumber) {
|
||||||
|
const { data: listComments } = await this.issue.listIssueComments(issueOrPrNumber);
|
||||||
|
return listComments.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,17 +101,22 @@ async function main() {
|
|||||||
.option('-t, --token [type]', 'token')
|
.option('-t, --token [type]', 'token')
|
||||||
.option('-h, --head [type]', 'head')
|
.option('-h, --head [type]', 'head')
|
||||||
.option('-r, --repo [type]', 'repo')
|
.option('-r, --repo [type]', 'repo')
|
||||||
|
.option('-c, --commit [type]', 'commit')
|
||||||
.option('-title, --title [type]', 'title')
|
.option('-title, --title [type]', 'title')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
const { token, title, head, repo } = program,
|
const { token, title, head, repo, commit } = program,
|
||||||
prCreator = new PrCreator(ORGANISATION, repo, token);
|
prCreator = new PrCreator(ORGANISATION, repo, token, commit);
|
||||||
|
|
||||||
if (!token || !head || !title) {
|
if (!token || !head || !title) {
|
||||||
throw new Error('Each of the parameters have to be provided. --token, --title, --head');
|
throw new Error('Each of the parameters have to be provided. --token, --title, --head');
|
||||||
}
|
}
|
||||||
|
const baseBranchName = 'develop';
|
||||||
|
|
||||||
return prCreator.create(title, head, 'develop');
|
const prNumber = await prCreator.createOrUpdate(title, head, baseBranchName, commit);
|
||||||
|
await prCreator.createComment(prNumber, head, baseBranchName, commit);
|
||||||
|
|
||||||
|
return prNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
@@ -14,6 +14,7 @@ show_help() {
|
|||||||
echo "-t or --token: Github ouath token"
|
echo "-t or --token: Github ouath token"
|
||||||
echo "-p or --pr: Originating jsapi PR number"
|
echo "-p or --pr: Originating jsapi PR number"
|
||||||
echo "-v or --version version to update"
|
echo "-v or --version version to update"
|
||||||
|
echo "-c or --commit The commit that the current build is testing"
|
||||||
}
|
}
|
||||||
|
|
||||||
set_token() {
|
set_token() {
|
||||||
@@ -28,6 +29,10 @@ version() {
|
|||||||
VERSION=$1
|
VERSION=$1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_commit() {
|
||||||
|
COMMIT=$1
|
||||||
|
}
|
||||||
|
|
||||||
update_dependency() {
|
update_dependency() {
|
||||||
PKG=$1
|
PKG=$1
|
||||||
PKG_VERSION=$(npm view $PKG@$VERSION version)
|
PKG_VERSION=$(npm view $PKG@$VERSION version)
|
||||||
@@ -91,7 +96,7 @@ update() {
|
|||||||
git push --force origin $BRANCH_TO_CREATE
|
git push --force origin $BRANCH_TO_CREATE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
node $BUILD_PIPELINE_DIR/pr-creator.js --token=$TOKEN --title="Update branch for ADF ${PR_NUMBER} and JS-API ${JS_API_INSTALLED} [ci:force]" --head=$BRANCH_TO_CREATE --repo=$NAME_REPO
|
node $BUILD_PIPELINE_DIR/pr-creator.js --token=$TOKEN --title="Update branch for ADF ${PR_NUMBER} and JS-API ${JS_API_INSTALLED} [ci:force]" --head=$BRANCH_TO_CREATE --repo=$NAME_REPO --commit=$COMMIT
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
rm -rf $TEMP_GENERATOR_DIR
|
rm -rf $TEMP_GENERATOR_DIR
|
||||||
@@ -103,6 +108,7 @@ while [[ $1 == -* ]]; do
|
|||||||
-t|--token) set_token $2; shift; shift;;
|
-t|--token) set_token $2; shift; shift;;
|
||||||
-p|--pr) set_pr $2; shift; shift;;
|
-p|--pr) set_pr $2; shift; shift;;
|
||||||
-v|--version) version $2; shift 2;;
|
-v|--version) version $2; shift 2;;
|
||||||
|
-c|--commit) set_commit $2; shift 2;;
|
||||||
-*) echo "invalid option: $1" 1>&2; show_help; exit 1;;
|
-*) echo "invalid option: $1" 1>&2; show_help; exit 1;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
Reference in New Issue
Block a user