Skip to content

Commit

Permalink
Merge branch 'dev' into users/csigs/hb_452267ed-f3ea-4b18-a9d2-7c2ed1…
Browse files Browse the repository at this point in the history
…7cef14_20240416133726729
  • Loading branch information
shimedh authored Apr 16, 2024
2 parents a960b82 + d1d4ed5 commit 3dfdd58
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions server/src/deployment-center/github/github.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,12 @@ export class GithubController {
await this._makeGetCallWithLinkAndOAuthHeaders(url, gitHubToken, res);
}

@Put('api/github/updateGitHubContent')
@HttpCode(200)
async updateGitHubContent(@Body('gitHubToken') gitHubToken: string, @Body('commit') commit: GitHubCommit) {
await this._commitGitHubFile(gitHubToken, commit);
}

private _getAuthorizationHeader(accessToken: string): { Authorization: string } {
return {
Authorization: `token ${accessToken}`,
Expand Down Expand Up @@ -821,6 +827,33 @@ export class GithubController {
}
}

private async _commitGitHubFile(gitHubToken: string, commit: GitHubCommit) {
const url = `${this.githubApiUrl}/repos/${commit.repoName}/contents/${commit.filePath}`;

const commitContent = {
message: commit.message,
content: commit.contentBase64Encoded,
sha: commit.sha,
branch: commit.branchName,
comitter: commit.committer,
};

try {
await this.httpService.put(url, commitContent, {
headers: this._getAuthorizationHeader(gitHubToken),
});
} catch (err) {
this.loggingService.error(
`Failed to commit GitHub '${commit.filePath}' on branch '${commit.branchName}' in repo '${commit.repoName}'.`
);

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

private _getEnvironment(hostUrl: string): Environments {
const hostUrlToLower = (hostUrl || '').toLocaleLowerCase();
for (const url in EnvironmentUrlMappings.urlToEnvironmentMap) {
Expand Down

0 comments on commit 3dfdd58

Please sign in to comment.