Skip to content

Commit

Permalink
feat: list commits before deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Sep 15, 2023
1 parent afbe717 commit fee3c5a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
18 changes: 15 additions & 3 deletions src/github/service/opensumi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,24 @@ export class OpenSumiOctoService extends GitHubService {
return workflow;
}

async getBotLastNCommitsText(n = 5) {
async getLastNCommitsText(options: {
owner: string;
repo: string;
ref?: string;
/**
* @default 5
*/
n?: number;
}) {
const { owner, repo, ref, n = 5 } = options;

const { data } = await this.octo.repos.listCommits({
owner: 'opensumi',
repo: 'github-bot',
owner,
repo,
sha: ref,
per_page: n,
});

const commits = data.map((c) => {
return {
sha: c.sha,
Expand Down
31 changes: 27 additions & 4 deletions src/im/commands/opensumi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ export function registerOpenSumiCommand(it: IMCommandCenter) {
const { app } = ctx;
let text = '';
try {
text = '\n\n' + (await app.opensumiOctoService.getBotLastNCommitsText());
text =
'\n\n' +
(await app.opensumiOctoService.getLastNCommitsText({
owner: 'opensumi',
repo: 'github-bot',
}));
} catch (error) {
console.error(
`getBotLastNCommitsText error: ${(error as Error).message}`,
Expand Down Expand Up @@ -69,7 +74,12 @@ export function registerOpenSumiCommand(it: IMCommandCenter) {
const { app } = ctx;
let text = '';
try {
text = '\n\n' + (await app.opensumiOctoService.getBotLastNCommitsText());
text =
'\n\n' +
(await app.opensumiOctoService.getLastNCommitsText({
owner: 'opensumi',
repo: 'github-bot',
}));
} catch (error) {
console.error(
`getBotLastNCommitsText error: ${(error as Error).message}`,
Expand Down Expand Up @@ -110,11 +120,18 @@ export function registerOpenSumiCommand(it: IMCommandCenter) {
if (ref) {
try {
await app.octoService.getRefInfoByRepo(ref, 'opensumi', 'core');

const text = await app.opensumiOctoService.getLastNCommitsText({
owner: 'opensumi',
repo: 'core',
ref,
});

await app.opensumiOctoService.releaseRCVersion(ref, workflowRef);
await bot.reply(
markdown(
'Starts releasing the release candidate',
`Starts releasing the [release candidate](https://github.com/opensumi/core/actions/workflows/${RC_WORKFLOW_FILE}) on ${ref}`,
`Starts releasing the [release candidate](https://github.com/opensumi/core/actions/workflows/${RC_WORKFLOW_FILE}) on ${ref}\n\n${text}`,
),
);
} catch (error) {
Expand Down Expand Up @@ -153,11 +170,17 @@ export function registerOpenSumiCommand(it: IMCommandCenter) {
if (ref) {
try {
await app.octoService.getRefInfoByRepo(ref, 'opensumi', 'core');
const text = await app.opensumiOctoService.getLastNCommitsText({
owner: 'opensumi',
repo: 'core',
ref,
});

await app.opensumiOctoService.releaseRCVersion(ref, workflowRef);
await bot.reply(
markdown(
'Starts releasing the release candidate',
`Starts releasing the [release candidate](https://github.com/opensumi/core/actions/workflows/${RC_WORKFLOW_FILE}) on ${ref}`,
`Starts releasing the [release candidate](https://github.com/opensumi/core/actions/workflows/${RC_WORKFLOW_FILE}) on ${ref}\n\n${text}`,
),
);
} catch (error) {
Expand Down

0 comments on commit fee3c5a

Please sign in to comment.