Skip to content

Commit

Permalink
feat(back): Gitlab Actions migration
Browse files Browse the repository at this point in the history
  • Loading branch information
EdenComp authored and RezaRahemtola committed Oct 30, 2023
1 parent de13d2b commit 7702cac
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions backend/back/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ import { CreateGoogleFormUpdateDescriptionArea1698654637708 } from "./workflows/
import { CreateGoogleFormConvertToQuizArea1698655334570 } from "./workflows/seed/1698655334570-CreateGoogleFormConvertToQuizArea";
import { CreateGoogleUpdateSpreadsheetTitleArea1698656017859 } from "./workflows/seed/1698656017859-CreateGoogleUpdateSpreadsheetTitleArea";
import { CreateLinearCreateIssueAreas1698614949784 } from "./workflows/seed/1698614949784-CreateLinearCreateIssueAreas";
import {
CreateGitlabCommitPRActions1698678924392
} from "./workflows/seed/1698678924392-CreateGitlabCommitPRActions";

dotenv.config();

Expand Down Expand Up @@ -126,6 +129,7 @@ export const DATA_SOURCE_OPTIONS: DataSourceOptions = {
CreateGoogleFormConvertToQuizArea1698655334570,
CreateGoogleUpdateSpreadsheetTitleArea1698656017859,
CreateLinearCreateIssueAreas1698614949784,
CreateGitlabCommitPRActions1698678924392,
],
synchronize: process.env.NODE_ENV === "development",
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import {ParametersFormFlowFieldDto} from "../../services/dto/area.dto";

export class CreateGitlabCommitPRActions1698678924392 implements MigrationInterface {

private readonly gitlabActionsParametersFormFlow: ParametersFormFlowFieldDto[] = [
{
name: "projectId",
type: "short-text",
required: true,
},
];

private readonly gitlabOnCommitParameters: string[] = ["author", "branch", "createdAt", "message", "url"];
private readonly gitlabOnPullRequestParameters: string[] = ["author", "base", "compare", "createdAt", "description", "title", "url"];

public async up(queryRunner: QueryRunner): Promise<void> {
const commitParams = `'{${this.gitlabOnCommitParameters.map((v) => `"${v}"`).join(",")}}'`
const pullRequestParams = `'{${this.gitlabOnPullRequestParameters.map((v) => `"${v}"`).join(",")}}'`

await queryRunner.query(
`INSERT INTO "area" ("id", "service_id", "is_action", "description", "parameters_form_flow", "parameters_return_flow")
VALUES ('on-commit', 'gitlab', true, 'Triggers when an commit is pushed on a Gitlab project', $1, ${commitParams}),
('on-pull-request-close', 'gitlab', true, 'Triggers when a merge request is closed on a Gitlab project', $1, ${pullRequestParams}),
('on-pull-request-create', 'gitlab', true, 'Triggers when a merge request is created on a Gitlab project', $1, ${pullRequestParams}),
('on-pull-request-merge', 'gitlab', true, 'Triggers when a merge request is merged on a Gitlab project', $1, ${pullRequestParams}),
('on-pull-request-reopen', 'gitlab', true, 'Triggers when a merge request is merged on a Gitlab project', $1, ${pullRequestParams})`,
[JSON.stringify(this.gitlabActionsParametersFormFlow)],
);

await queryRunner.query(
`INSERT INTO "area_service_scopes_needed_service_scope" ("area_id", "area_service_id", "service_scope_id", "service_scope_service_id")
VALUES ('on-commit', 'gitlab', 'api', 'gitlab'),
('on-pull-request-close', 'gitlab', 'api', 'gitlab'),
('on-pull-request-create', 'gitlab', 'api', 'gitlab'),
('on-pull-request-merge', 'github', 'api', 'gitlab'),
('on-pull-request-merge', 'gitlab', 'api', 'gitlab')
`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM "area"
WHERE service_id = 'gitlab'
AND id IN ('on-commit', 'on-pull-request-close', 'on-pull-request-create', 'on-pull-request-merge', 'on-pull-request-reopen')`,
);
}

}

0 comments on commit 7702cac

Please sign in to comment.