From 2ae90a0ee8e81024cf4c0336d8e89eaf0c7d7986 Mon Sep 17 00:00:00 2001 From: Endre Sukosd Date: Fri, 14 Feb 2020 12:47:11 +0100 Subject: [PATCH] fix: format text --- .github/workflows/fast_forward.yml | 4 +++- action.yml | 12 ++++++++++-- dist/fast_forward_action.js | 24 ++++++++---------------- dist/index.js | 6 ++++-- src/fast_forward_action.ts | 24 +++++++----------------- src/index.ts | 5 +++-- 6 files changed, 35 insertions(+), 40 deletions(-) diff --git a/.github/workflows/fast_forward.yml b/.github/workflows/fast_forward.yml index 0eefa937..775efad4 100644 --- a/.github/workflows/fast_forward.yml +++ b/.github/workflows/fast_forward.yml @@ -18,6 +18,8 @@ jobs: with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} success_message: 'Success! Fast forwarded ***target_base*** to ***source_head***! ```git checkout target_base && git merge source_head --ff-only``` ' - failure_message: 'Failed! Possible reasons: 1) ***ff_fail_reason*** 2) Review required, pull-request is not approved 3) Some status checks were not successful (like build check) ' + failure_message: 'Failed! Cannot do fast forward!' + failure_message_outdated: 'Failed! Possible reasons: ***1)Your feature branch ```source_head``` is outdated***. You need to rebase ```git checkout source_head && git pull --rebase origin prod_branch && git push --force``` ***2)Review required***, pull-request is not approved ***3)Checks were not successful*** (build status check failed)' + failure_message_in_use: 'Failed! Possible reasons: ***1)```stage_branch``` is currently in use***. Another feature validation is ongoing. You need to wait. Later, when integration finishes, you will need to rebase ```git checkout source_head && git pull --rebase origin prod_branch && git push --force``` ***2)Review required***, pull-request is not approved ***3)Checks were not successful*** (build status check failed)' production_branch: 'master' staging_branch: 'stage' \ No newline at end of file diff --git a/action.yml b/action.yml index d3786322..9f331a1e 100644 --- a/action.yml +++ b/action.yml @@ -4,9 +4,17 @@ inputs: GITHUB_TOKEN: description: 'Automatically provided token, that can be used to authenticate on behalf of the GitHub action, with permissions limited to the repository that contains your workflow' success_message: - description: 'Will be commented on the pull request, if fast forward succeeds' + description: 'Generic success message, will be commented on the pull request, if fast forward succeeds' failure_message: - description: 'Will be commented on the pull request, if fast forward fails' + description: 'Generic failure message, Will be commented on the pull request, if fast forward fails' + failure_message_outdated: + description: 'Optional, failure message, when pr source branch is outdated, staging and prod are ahead' + failure_message_in_use: + description: 'Optional, failure message, when staging is in use, ahead of productin' + production_branch: + description: 'Optional, production branch name' + staging_branch: + description: 'Optional, staging-preproduction branch name' runs: using: 'node12' main: 'dist/index.js' diff --git a/dist/fast_forward_action.js b/dist/fast_forward_action.js index 2625ff6a..27aa45d7 100644 --- a/dist/fast_forward_action.js +++ b/dist/fast_forward_action.js @@ -42,9 +42,9 @@ var FastForwardAction = /** @class */ (function () { this.client = client; } ; - FastForwardAction.prototype.execute_async = function (client, successMessage, failureMessage, prod_branch, stage_branch) { + FastForwardAction.prototype.execute_async = function (client, successMessage, failure_message_outdated, failure_message_in_use, prod_branch, stage_branch) { return __awaiter(this, void 0, void 0, function () { - var pr_number, stageEqualsProd, source_head, target_base, error_1, ff_fail_reason, updated_message; + var pr_number, stageEqualsProd, source_head, target_base, error_1, failure_message, updated_message_1, updated_message; return __generator(this, function (_a) { switch (_a.label) { case 0: @@ -76,19 +76,14 @@ var FastForwardAction = /** @class */ (function () { return [4 /*yield*/, client.set_pull_request_status(pr_number, "failure")]; case 9: _a.sent(); - ff_fail_reason = void 0; - if (stageEqualsProd) { - ff_fail_reason = "Your feature branch ```" + source_head + "``` is outdated. Another feature has been merged into ```" + prod_branch + "``` before yours. You need to rebase your feature branch (```git checkout " + source_head + " && git pull --rebase origin " + prod_branch + " && git push --force```)"; - } - else { - ff_fail_reason = "Integration is ongoing. Another feature validation is in progress and using an updated ```" + stage_branch + "```. You need to wait until these changes will be merged into ```" + prod_branch + "```. Then rebase your feature branch (```git checkout " + source_head + " && git pull --rebase origin " + prod_branch + " && git push --force```)"; - } - return [4 /*yield*/, client.comment_on_pull_request_async(pr_number, this.insert_ff_fail_reason_names(failureMessage, ff_fail_reason))]; + failure_message = stageEqualsProd ? failure_message_outdated : failure_message_in_use; + updated_message_1 = this.insert_branch_names(failure_message, source_head, target_base, prod_branch, stage_branch); + return [4 /*yield*/, client.comment_on_pull_request_async(pr_number, updated_message_1)]; case 10: _a.sent(); return [2 /*return*/]; case 11: - updated_message = this.insert_branch_names(successMessage, source_head, target_base); + updated_message = this.insert_branch_names(successMessage, source_head, target_base, prod_branch, stage_branch); return [4 /*yield*/, client.comment_on_pull_request_async(pr_number, updated_message)]; case 12: _a.sent(); @@ -97,11 +92,8 @@ var FastForwardAction = /** @class */ (function () { }); }); }; - FastForwardAction.prototype.insert_branch_names = function (message, source, target) { - return message.replace(/source_head/g, source).replace(/target_base/g, target); - }; - FastForwardAction.prototype.insert_ff_fail_reason_names = function (message, ff_fail_reason) { - return message.replace(/ff_fail_reason/g, ff_fail_reason); + FastForwardAction.prototype.insert_branch_names = function (message, source, target, prod_branch, stage_branch) { + return message.replace(/source_head/g, source).replace(/target_base/g, target).replace(/prod_branch/g, prod_branch).replace(/stage_branch/g, stage_branch); }; return FastForwardAction; }()); diff --git a/dist/index.js b/dist/index.js index 4640e4e8..f3605624 100644 --- a/dist/index.js +++ b/dist/index.js @@ -49,18 +49,20 @@ var github_client_wrapper_1 = require("./github_client_wrapper"); var fast_forward_action_1 = require("./fast_forward_action"); function run() { return __awaiter(this, void 0, void 0, function () { - var github_token, success_message, failure_message, prod_branch, stage_branch, client, fastForward; + var github_token, success_message, failure_message, failure_message_outdated, failure_message_in_use, prod_branch, stage_branch, client, fastForward; return __generator(this, function (_a) { switch (_a.label) { case 0: github_token = core.getInput('GITHUB_TOKEN'); success_message = core.getInput('success_message'); failure_message = core.getInput('failure_message'); + failure_message_outdated = core.getInput('failure_message_outdated') || failure_message; + failure_message_in_use = core.getInput('failure_message_in_use') || failure_message; prod_branch = core.getInput('production_branch'); stage_branch = core.getInput('staging_branch'); client = new github_client_wrapper_1.GitHubClientWrapper(github.context, github_token); fastForward = new fast_forward_action_1.FastForwardAction(client); - return [4 /*yield*/, fastForward.execute_async(client, success_message, failure_message, prod_branch, stage_branch)]; + return [4 /*yield*/, fastForward.execute_async(client, success_message, failure_message_outdated, failure_message_in_use, prod_branch, stage_branch)]; case 1: _a.sent(); return [2 /*return*/]; diff --git a/src/fast_forward_action.ts b/src/fast_forward_action.ts index 70061e90..40f13972 100644 --- a/src/fast_forward_action.ts +++ b/src/fast_forward_action.ts @@ -6,7 +6,7 @@ export class FastForwardAction{ this.client = client; }; - async execute_async(client: GitHubClient, successMessage: string, failureMessage: string, prod_branch: string, stage_branch: string): Promise{ + async execute_async(client: GitHubClient, successMessage: string, failure_message_outdated: string, failure_message_in_use: string, prod_branch: string, stage_branch: string): Promise{ const pr_number = client.get_current_pull_request_number(); await client.set_pull_request_status(pr_number, "pending"); @@ -22,30 +22,20 @@ export class FastForwardAction{ } catch(error){ await client.set_pull_request_status(pr_number, "failure"); - let ff_fail_reason; - - if (stageEqualsProd){ - ff_fail_reason = `Your feature branch \`\`\`${source_head}\`\`\` is outdated. Another feature has been merged into \`\`\`${prod_branch}\`\`\` before yours. You need to rebase your feature branch (\`\`\`git checkout ${source_head} && git pull --rebase origin ${prod_branch} && git push --force\`\`\`)` - } else { - ff_fail_reason = `Integration is ongoing. Another feature validation is in progress and using an updated \`\`\`${stage_branch}\`\`\`. You need to wait until these changes will be merged into \`\`\`${prod_branch}\`\`\`. Then rebase your feature branch (\`\`\`git checkout ${source_head} && git pull --rebase origin ${prod_branch} && git push --force\`\`\`)` - } - - await client.comment_on_pull_request_async(pr_number, this.insert_ff_fail_reason_names(failureMessage, ff_fail_reason)); + const failure_message = stageEqualsProd ? failure_message_outdated : failure_message_in_use; + const updated_message = this.insert_branch_names(failure_message, source_head, target_base, prod_branch, stage_branch); + await client.comment_on_pull_request_async(pr_number, updated_message); return; } - const updated_message = this.insert_branch_names(successMessage, source_head, target_base); + const updated_message = this.insert_branch_names(successMessage, source_head, target_base, prod_branch, stage_branch); await client.comment_on_pull_request_async(pr_number, updated_message); } - insert_branch_names(message: string, source: string, target: string): string{ - return message.replace(/source_head/g, source).replace(/target_base/g, target); - } - - insert_ff_fail_reason_names(message: string, ff_fail_reason: string): string{ - return message.replace(/ff_fail_reason/g, ff_fail_reason); + insert_branch_names(message: string, source: string, target: string, prod_branch: string, stage_branch: string): string{ + return message.replace(/source_head/g, source).replace(/target_base/g, target).replace(/prod_branch/g, prod_branch).replace(/stage_branch/g, stage_branch); } }; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 0b8d1a9c..dd59fc78 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,14 +7,15 @@ async function run(): Promise{ const github_token = core.getInput('GITHUB_TOKEN'); const success_message = core.getInput('success_message'); const failure_message = core.getInput('failure_message'); + const failure_message_outdated = core.getInput('failure_message_outdated') || failure_message; + const failure_message_in_use = core.getInput('failure_message_in_use') || failure_message; const prod_branch = core.getInput('production_branch'); const stage_branch = core.getInput('staging_branch'); - const client = new GitHubClientWrapper(github.context , github_token); const fastForward = new FastForwardAction(client); - await fastForward.execute_async(client, success_message, failure_message, prod_branch, stage_branch); + await fastForward.execute_async(client, success_message, failure_message_outdated, failure_message_in_use, prod_branch, stage_branch); }