alfresco-ng2-components/scripts/github/update/adf-same-commit-verify.js
Maurizio Cacace fc224713f2
AAE-11918A - remove travis env var (#8312)
* AAE-11918 - travis_branch env removal

* AAE-11918 - travis_branch env removal

* event_type and travis_pull_request_branch  env removal

* e travis_build_dir, travis_build_number, travis_commit  env removal

* rename scripts path

* remove .travis file

* remove .travis file

* remove .travis file

* just a commit

* trying to fix e2e test

* fix e2e issue

* remove action load travis env

* with action travis env var load

* remove action travis load env vars

* remove action travis load env vars

* remove action travis load env vars

* last check

* test release flow in dry-run

* final check for review

* fix env variables

* fix env variables

* fix env variables

* remove devel flag

* revert renaming action facade

* git mv commit

* git mv commit
2023-02-28 15:36:22 +01:00

72 lines
2.1 KiB
JavaScript

#!/usr/bin/env node
const GitHub = require('github-api');
let program = require('commander');
const ORGANISATION = 'Alfresco';
const ORIGIN_REPO = 'alfresco-ng2-components';
class PrCreator {
constructor(githubUser, githubRepo, token, commit) {
this.github = new GitHub({token});
this.repoOrigin = this.github.getRepo(githubUser, ORIGIN_REPO);
this.repoDestination = this.github.getRepo(githubUser, githubRepo);
this.commit = commit;
}
async getShaClosedPr(head, base) {
return this.getShaPr(head, base, 'closed');
}
async getShaOpenPr(head, base) {
return this.getShaPr(head, base, 'open');
}
async getShaPr(head, base, status) {
const { data: closedUpstreamPRs } = await this.repoDestination.listPullRequests({ state: status, head: `${ORGANISATION}:${head}`, base });
if (closedUpstreamPRs.length > 0) {
const latestClosedUpstream = closedUpstreamPRs[0];
return latestClosedUpstream.body.split(':')[1].trim();
}
return '';
}
}
async function main() {
program
.version('0.1.0')
.option('--host [type]', 'Remote environment host adf.lab.com ')
.option('-t, --token [type]', 'token')
.option('-h, --head [type]', 'head')
.option('-r, --repo [type]', 'repo')
.option('-c, --commit [type]', 'commit')
.parse(process.argv);
const { token, head, repo, commit } = program,
prCreator = new PrCreator(ORGANISATION, repo, token, commit);
const baseBranchName = 'develop';
const shaOpen = await prCreator.getShaOpenPr(head, baseBranchName);
const shaClosed = await prCreator.getShaClosedPr(head, baseBranchName);
if (shaOpen === commit || shaClosed === commit) {
console.log('ADF sha already exist');
return 'true';
}
return 'false';
}
main()
.then(result => {
process.stdout.write(result);
process.exit(0);
})
.catch(error => {
console.error(error.response.status);
console.error(error.response.statusText);
process.exit(1);
});