Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitLab - check comment body size #1350

Merged
merged 7 commits into from
Feb 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
dacbd marked this conversation as resolved.
Show resolved Hide resolved
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