Skip to content

Commit

Permalink
GitLab - check comment body size (#1350)
Browse files Browse the repository at this point in the history
* check body sizew

* use const

* onger error msg

* Update src/drivers/gitlab.js
  • Loading branch information
dacbd committed Feb 21, 2023
1 parent 98bf892 commit 1be24ed
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/drivers/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const { fetchUploadData, download, gpuPresent } = require('../utils');
const { CI_JOB_ID, CI_PIPELINE_ID, IN_DOCKER } = process.env;

const API_VER = 'v4';
const MAX_COMMENT_SIZE = 1000000;
const ERROR_COMMENT_SIZE =
'GitLab Comment is too large, this is likely caused by the `--publish-native` flag causing the comment to pass the 1M character limit';

class Gitlab {
constructor(opts = {}) {
const { repo, token } = opts;
Expand Down Expand Up @@ -69,6 +73,8 @@ class Gitlab {
async commitCommentCreate(opts = {}) {
const { commitSha, report } = opts;

if (report.length >= MAX_COMMENT_SIZE) throw new Error(ERROR_COMMENT_SIZE);

const projectPath = await this.projectPath();
const endpoint = `/projects/${projectPath}/repository/commits/${commitSha}/comments`;
const body = new URLSearchParams();
Expand Down Expand Up @@ -334,6 +340,8 @@ class Gitlab {
const projectPath = await this.projectPath();
const { issueId, report, id: commentId } = opts;

if (report.length >= MAX_COMMENT_SIZE) throw new Error(ERROR_COMMENT_SIZE);

const endpoint =
`/projects/${projectPath}/issues/${issueId}/notes` +
`${commentId ? '/' + commentId : ''}`;
Expand Down Expand Up @@ -379,6 +387,8 @@ class Gitlab {
const projectPath = await this.projectPath();
const { report, prNumber } = opts;

if (report.length >= MAX_COMMENT_SIZE) throw new Error(ERROR_COMMENT_SIZE);

const endpoint = `/projects/${projectPath}/merge_requests/${prNumber}/notes`;
const body = new URLSearchParams();
body.append('body', report);
Expand All @@ -396,6 +406,8 @@ class Gitlab {
const projectPath = await this.projectPath();
const { report, prNumber, id: commentId } = opts;

if (report.length >= MAX_COMMENT_SIZE) throw new Error(ERROR_COMMENT_SIZE);

const endpoint = `/projects/${projectPath}/merge_requests/${prNumber}/notes/${commentId}`;
const body = new URLSearchParams();
body.append('body', report);
Expand Down

0 comments on commit 1be24ed

Please sign in to comment.