Skip to content

Commit

Permalink
feat: support sync codeblitz packages
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed May 30, 2024
1 parent 6ec6a42 commit 2f0da3b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 10 deletions.
14 changes: 14 additions & 0 deletions src/constants/opensumi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ export namespace ActionsRepo {
workflow_id: MONTHLY_REPORT_FILE,
ref: 'main',
};

export const SYNC_FILE = 'sync.yml';
export const SYNC_WORKFLOW = {
...info,
workflow_id: SYNC_FILE,
ref: 'main',
};

export const SYNC_CODEBLITZ_FILE = 'codeblitz-sync.yml';
export const SYNC_CODEBLITZ_WORKFLOW = {
...info,
workflow_id: SYNC_CODEBLITZ_FILE,
ref: 'main',
};
}

export function getActionsUrl({
Expand Down
30 changes: 24 additions & 6 deletions src/github/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Octokit } from '@octokit/rest';
import { HandlerFunction } from '@octokit/webhooks/dist-types/types';

import { PrivilegeEvent } from '@/constants';
import { VERSION_SYNC_KEYWORD } from '@/constants/opensumi';
import { ActionsRepo, VERSION_SYNC_KEYWORD } from '@/constants/opensumi';
import Environment from '@/env';
import { AppSetting } from '@/kv/types';
import { GitHubService } from '@opensumi/octo-service';
Expand Down Expand Up @@ -51,13 +51,30 @@ export class App {
);
}

handleSyncVersion = async (data: string) => {
handleSyncVersion = async (fullname: string, data: string) => {
const [tag, version] = data.split(' | ');
await this.opensumiOctoService.syncVersion(version);

let file = '';
let name = '';
switch (fullname) {
case 'opensumi/core':
file = ActionsRepo.SYNC_FILE;
name = 'opensumi';
await this.opensumiOctoService.syncVersion(version);
break;
case 'opensumi/codeblitz':
file = ActionsRepo.SYNC_CODEBLITZ_FILE;
name = 'codeblitz';
await this.opensumiOctoService.syncCodeblitzVersion(version);
break;
default:
throw new Error('unknown repo');
}

await sendToDing(
{
title: 'Starts Synchronizing',
text: `${tag} has published. [starts synchronizing packages@${version} to npmmirror](https://github.com/opensumi/actions/actions/workflows/sync.yml)`,
text: `[${fullname}] ${tag} has published. [starts synchronizing ${name} packages@${version} to npmmirror](https://github.com/opensumi/actions/actions/workflows/${file})`,
},
PrivilegeEvent,
this.ctx.setting,
Expand All @@ -77,7 +94,8 @@ export class App {
}
>
>[0]) => {
const { comment } = payload;
const { comment, repository } = payload;
const fullname = repository.full_name;

await issueCc.tryHandle(
comment.body,
Expand All @@ -97,7 +115,7 @@ export class App {
const commands = parseCommandInMarkdownComments(comment.body);
if (commands) {
if (commands[VERSION_SYNC_KEYWORD]) {
await this.handleSyncVersion(commands[VERSION_SYNC_KEYWORD]);
await this.handleSyncVersion(fullname, commands[VERSION_SYNC_KEYWORD]);
}
}
};
Expand Down
35 changes: 31 additions & 4 deletions src/github/service/opensumi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,38 @@ export class OpenSumiOctoService extends GitHubService {
if (version) {
inputs.version = version;
}

const _workflow = {
...ActionsRepo.SYNC_WORKFLOW,
};

if (workflowRef) {
_workflow.ref = workflowRef;
}

const workflow = await this.octo.actions.createWorkflowDispatch({
owner: 'opensumi',
repo: 'actions',
workflow_id: 'sync.yml',
ref: workflowRef,
..._workflow,
inputs,
});
return workflow;
}

async syncCodeblitzVersion(version?: string, workflowRef = 'main') {
const inputs = {} as Record<string, any>;
if (version) {
inputs.version = version;
}

const _workflow = {
...ActionsRepo.SYNC_CODEBLITZ_WORKFLOW,
};

if (workflowRef) {
_workflow.ref = workflowRef;
}

const workflow = await this.octo.actions.createWorkflowDispatch({
..._workflow,
inputs,
});
return workflow;
Expand Down

0 comments on commit 2f0da3b

Please sign in to comment.