Skip to content

Commit

Permalink
fix: format text
Browse files Browse the repository at this point in the history
  • Loading branch information
endre-spotlab committed Feb 14, 2020
1 parent 3b2342c commit 2ae90a0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 40 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/fast_forward.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
12 changes: 10 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
24 changes: 8 additions & 16 deletions dist/fast_forward_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}());
Expand Down
6 changes: 4 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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*/];
Expand Down
24 changes: 7 additions & 17 deletions src/fast_forward_action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>{
async execute_async(client: GitHubClient, successMessage: string, failure_message_outdated: string, failure_message_in_use: string, prod_branch: string, stage_branch: string): Promise<void>{
const pr_number = client.get_current_pull_request_number();
await client.set_pull_request_status(pr_number, "pending");

Expand All @@ -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);
}

};
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ async function run(): Promise<void>{
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);

}

Expand Down

0 comments on commit 2ae90a0

Please sign in to comment.