export async function postResultsToPRComments()

in gitlab/src/utils.ts [336:385]


export async function postResultsToPRComments(
  toolName: string,
  sourceDir: string,
  content: string,
  hasIssues: boolean,
  postComment: boolean
): Promise<void> {
  if (!postComment) {
    return
  }
  try {
    const comment_tag_pattern = getCommentTag(toolName, sourceDir)
    const body = `${content}\n${comment_tag_pattern}`

    const result = await findCommentByTag(comment_tag_pattern)
    let discussionId = result.discussionId
    const noteId = result.noteId

    const api = getGitlabApi()
    const mergeRequestId = getEnvVariable('CI_MERGE_REQUEST_IID')
    const projectId = getEnvVariable('CI_PROJECT_ID')
    if (discussionId === undefined || noteId === undefined) {
      discussionId = (
        await api.MergeRequestDiscussions.create(
          projectId,
          mergeRequestId,
          body
        )
      ).id
    } else {
      await api.MergeRequestDiscussions.editNote(
        projectId,
        mergeRequestId,
        discussionId,
        noteId,
        {
          body: body
        }
      )
    }
    await api.MergeRequestDiscussions.resolve(
      projectId,
      mergeRequestId,
      discussionId,
      !hasIssues
    )
  } catch (e) {
    console.warn(`Was not able to post comment to PR: ${(e as Error).message}`)
  }
}