Skip to content

Commit

Permalink
feat: support release next in pr for codeblitz
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed May 30, 2024
1 parent a6afaf1 commit e95f56a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/constants/opensumi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export namespace ActionsRepo {
ref: 'main',
};

export const CODEBLITZ_PR_NEXT_RELEASE_FILE = 'codeblitz-release-next.yml';
export const CODEBLITZ_PR_NEXT_WORKFLOW = {
...info,
workflow_id: CODEBLITZ_PR_NEXT_RELEASE_FILE,
ref: 'main',
};

export const RELEASE_NEXT_BY_REF = 'release-next-by-ref.yml';
export const RELEASE_NEXT_BY_REF_WORKFLOW = {
...info,
Expand Down
13 changes: 8 additions & 5 deletions src/github/commands/pullRequests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ export function extractTargetBranchNameFromCommand(str: string) {
return;
}

const allowedRepo = new Set<string>(['opensumi/core']);
const backportAllowedRepo = new Set<string>(['opensumi/core']);

function constrainRepo(fullname: string) {
const allowedRepo = new Set<string>(['opensumi/core', 'opensumi/codeblitz']);

function constraintRepo(fullname: string, allowedRepo: Set<string>) {
if (!allowedRepo.has(fullname)) {
throw new StopError('This command is not allowed in this repository');
}
Expand All @@ -38,7 +40,7 @@ export function registerPullRequestCommand(it: GitHubCommandCenter) {
kBackportKeyword,
async (ctx) => {
const { app, payload } = ctx;
constrainRepo(payload.repository.full_name);
constraintRepo(payload.repository.full_name, backportAllowedRepo);

const { issue } = payload;

Expand Down Expand Up @@ -102,8 +104,8 @@ Please see: <${getActionsUrl(ActionsRepo.BACKPORT_PR_WORKFLOW)}>`,
const { app, payload } = ctx;
const owner = payload.repository.owner.login;
const repo = payload.repository.name;

constrainRepo(payload.repository.full_name);
const fullname = payload.repository.full_name;
constraintRepo(fullname, allowedRepo);

const user = payload.sender.login;
let userHaveWritePerm = await app.octoService.checkRepoWritePermission(
Expand Down Expand Up @@ -150,6 +152,7 @@ Please see: <${getActionsUrl(ActionsRepo.BACKPORT_PR_WORKFLOW)}>`,

await app.opensumiOctoService.prNextRelease({
pull_number: issue.number,
fullname,
});
await app.createReactionForIssueComment(ctx, 'eyes');
});
Expand Down
23 changes: 20 additions & 3 deletions src/github/service/opensumi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionsRepo, RepoInfo } from '@/constants/opensumi';
import { ActionsRepo } from '@/constants/opensumi';
import { GitHubService } from '@opensumi/octo-service';

import { firstLine } from '../renderer/line';
Expand Down Expand Up @@ -107,9 +107,26 @@ export class OpenSumiOctoService extends GitHubService {
return workflow;
}

async prNextRelease({ pull_number }: { pull_number: number }) {
async prNextRelease({
pull_number,
fullname,
}: {
pull_number: number;
fullname: string;
}) {
let workflowInfo: any;

switch (fullname) {
case 'opensumi/core':
workflowInfo = ActionsRepo.PR_NEXT_WORKFLOW;
break;
case 'opensumi/codeblitz':
workflowInfo = ActionsRepo.CODEBLITZ_PR_NEXT_WORKFLOW;
break;
}

const workflow = await this.octo.actions.createWorkflowDispatch({
...ActionsRepo.PR_NEXT_WORKFLOW,
...workflowInfo,
inputs: {
pull_number: pull_number.toString(),
},
Expand Down

0 comments on commit e95f56a

Please sign in to comment.