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 4 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
13 changes: 13 additions & 0 deletions src/drivers/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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
class Gitlab {
constructor(opts = {}) {
const { repo, token } = opts;
Expand Down Expand Up @@ -69,6 +70,9 @@ class Gitlab {
async commitCommentCreate(opts = {}) {
const { commitSha, report } = opts;

if (report.length >= MAX_COMMENT_SIZE)
throw new Error('GitLab Comment too Large');
dacbd marked this conversation as resolved.
Show resolved Hide resolved
dacbd marked this conversation as resolved.
Show resolved Hide resolved

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

if (report.length >= MAX_COMMENT_SIZE)
throw new Error('GitLab Comment too Large');

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

if (report.length >= MAX_COMMENT_SIZE)
throw new Error('GitLab Comment too Large');

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

if (report.length >= MAX_COMMENT_SIZE)
throw new Error('GitLab Comment too Large');

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