Skip to content

Commit

Permalink
Add get logs and get workflow run apis (#7427)
Browse files Browse the repository at this point in the history
* add get logs api

* remove return

---------

Co-authored-by: Qi Liu <[email protected]>
  • Loading branch information
liuqidake and Qi Liu authored Oct 11, 2023
1 parent 2abc336 commit e9f1cb0
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions server/src/deployment-center/github/github.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,63 @@ export class GithubController {
await this._makeGetCallWithLinkAndOAuthHeaders(url, gitHubToken, res);
}

@Post('api/github/getWorkflowRunLogs')
@HttpCode(200)
async getJobLogs(
@Body('gitHubToken') gitHubToken: string,
@Body('org') org: string,
@Body('repo') repo: string,
@Body('runId') runId: number,
@Res() res
) {
const url = `${this.githubApiUrl}/repos/${org}/${repo}/actions/runs/${runId}/logs`;
try {
await this.httpService
.get(url, {
headers: this._getAuthorizationHeader(gitHubToken),
responseType: 'arraybuffer',
})
.then(response => {
res.json(response.data);
});
} catch (err) {
this.loggingService.error(`Failed to get workflow run logs.`);

if (err.response) {
throw new HttpException(err.response.data, err.response.status);
}
throw new HttpException(err, 500);
}
}

@Post('api/github/getWorkflowRun')
@HttpCode(200)
async getWorkflowRun(
@Body('gitHubToken') gitHubToken: string,
@Body('org') org: string,
@Body('repo') repo: string,
@Body('runId') runId: number,
@Res() res
) {
const url = `${this.githubApiUrl}/repos/${org}/${repo}/actions/runs/${runId}`;
try {
await this.httpService
.get(url, {
headers: this._getAuthorizationHeader(gitHubToken),
})
.then(response => {
res.json(response.data);
});
} catch (err) {
this.loggingService.error(`Failed to get workflow run.`);

if (err.response) {
throw new HttpException(err.response.data, err.response.status);
}
throw new HttpException(err, 500);
}
}

@Post('api/github/deleteWorkflowRun')
@HttpCode(200)
async deleteWorkflowRun(
Expand Down

0 comments on commit e9f1cb0

Please sign in to comment.