diff --git a/package-lock.json b/package-lock.json index 3428373..2b50ba6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "@jcroall/synopsys-sig-node", + "name": "synopsys-sig-node", "version": "1.1.70-beta.2", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "@jcroall/synopsys-sig-node", + "name": "synopsys-sig-node", "version": "1.1.70-beta.2", "license": "Apache-2.0", "dependencies": { @@ -28,7 +28,7 @@ "winston": "^3.6.0" }, "devDependencies": { - "@types/node": "^17.0.21", + "@types/node": "^17.0.45", "prettier": "^2.5.1" } }, @@ -333,9 +333,9 @@ } }, "node_modules/@types/node": { - "version": "17.0.21", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.21.tgz", - "integrity": "sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ==" + "version": "17.0.45", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.45.tgz", + "integrity": "sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==" }, "node_modules/@types/responselike": { "version": "1.0.0", @@ -2331,9 +2331,9 @@ } }, "@types/node": { - "version": "17.0.21", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.21.tgz", - "integrity": "sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ==" + "version": "17.0.45", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.45.tgz", + "integrity": "sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==" }, "@types/responselike": { "version": "1.0.0", diff --git a/package.json b/package.json index 42c4acd..2fabba1 100644 --- a/package.json +++ b/package.json @@ -11,15 +11,15 @@ "test": "echo \"Error: no test specified\" && exit 1", "all": "npm run build && npm run format" }, - "main": "dist/index.js", - "types": "dist/index.d.js", + "main": "lib/index.js", + "types": "lib/index.d.js", "files": [ "lib" ], "author": "Synopsys Community", "license": "Apache-2.0", "devDependencies": { - "@types/node": "^17.0.21", + "@types/node": "^17.0.45", "prettier": "^2.5.1" }, "dependencies": { diff --git a/src/coverity/coverity-api.ts b/src/coverity/coverity-api.ts index c34487d..ec52c1b 100644 --- a/src/coverity/coverity-api.ts +++ b/src/coverity/coverity-api.ts @@ -4,6 +4,8 @@ import {BasicCredentialHandler} from 'typed-rest-client/Handlers' import {RestClient} from 'typed-rest-client/RestClient' export const KEY_CID = 'cid' +export const KEY_DISPLAY_IMPACT = 'displayImpact' +export const KEY_DISPLAY_TYPE = 'displayType' export const KEY_MERGE_KEY = 'mergeKey' export const KEY_ACTION = 'action' export const KEY_CLASSIFICATION = 'classification' @@ -85,19 +87,23 @@ export class CoverityApiService { ] } ], - columns: [KEY_CID, KEY_MERGE_KEY, KEY_ACTION, KEY_CLASSIFICATION, KEY_FIRST_SNAPSHOT_ID, KEY_LAST_SNAPSHOT_ID] + columns: [KEY_CID, KEY_DISPLAY_IMPACT, KEY_DISPLAY_TYPE, KEY_MERGE_KEY, KEY_ACTION, KEY_CLASSIFICATION, + KEY_FIRST_SNAPSHOT_ID, KEY_LAST_SNAPSHOT_ID] } const queryParameters: IRequestQueryParams = { params: { locale: 'en_us', - offset, + offset: offset, rowCount: limit, includeColumnLabels: 'true', queryType: 'bySnapshot', sortOrder: 'asc' } } - const response = await this.restClient.create('/api/v2/issues/search', requestBody, {queryParameters}) + // Maybe bug in RestClient as queryParameters are treated as headers not as parameters + //const response = await this.restClient.create('/api/v2/issues/search', requestBody, {queryParameters}) + const apiSearch = `/api/v2/issues/search?offset=${offset}&rowCount=${limit}&local=en_us&includeColumnLabels=true&queryType=bySnapshot&sortOrder=asc` + const response = await this.restClient.create(apiSearch, requestBody) if (response.statusCode < 200 || response.statusCode >= 300) { debug(`Coverity response error: ${response.result}`) return Promise.reject(`Failed to retrieve issues from Coverity for project '${projectName}': ${response.statusCode}`) diff --git a/src/github/github-context.ts b/src/github/github-context.ts index 4371fdf..30b972f 100644 --- a/src/github/github-context.ts +++ b/src/github/github-context.ts @@ -1,5 +1,5 @@ import { context } from '@actions/github' -import { PullRequest } from '../_namespaces/Github' +import { PullRequest } from '../_namespaces/github' const prEvents = ['pull_request', 'pull_request_review', 'pull_request_review_comment'] diff --git a/src/gitlab/comment.ts b/src/gitlab/comment.ts new file mode 100644 index 0000000..c52ebda --- /dev/null +++ b/src/gitlab/comment.ts @@ -0,0 +1,27 @@ +import {logger} from "../SIGLogger"; +import {Gitlab} from '@gitbeaker/node' +import {CommentSchema} from '@gitbeaker/core/dist/types/resources/Commits' + +export async function gitlabGetExistingReviewComment(gitlab_url: string, gitlab_token: string, project_id: string, + commit_sha: string): Promise { + const api = new Gitlab({host: gitlab_url, token: gitlab_token}) + let res = await api.Commits.comments(project_id, commit_sha) + if (res[0].note === undefined || res[0].note === '') { + const err_message = 'Could not get the existing review comment. Project: ' + project_id + ' Sha: ' + commit_sha + logger.debug(err_message) + throw new Error(err_message) + } + return Promise.resolve(res) +} + +export async function gitlabUpdateExistingReviewComment(gitlab_url: string, gitlab_token: string, project_id: string, + commit_sha: string, comment: string): Promise { + const api = new Gitlab({host: gitlab_url, token: gitlab_token}) + const res = await api.Commits.createComment(project_id, commit_sha, comment) + if (res.note === undefined || res.note === '') { + const err_message = 'Could not update the existing review comment. Project: ' + project_id + ' Sha: ' + commit_sha + logger.debug(err_message) + throw new Error(err_message) + } + return Promise.resolve(res) +} diff --git a/src/index.ts b/src/index.ts index 46c853b..ba2005d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -53,6 +53,10 @@ export { export { gitlabGetProject, } from './gitlab/gitlab-utils' +export { + gitlabUpdateExistingReviewComment, + gitlabGetExistingReviewComment +} from './gitlab/comment' // Black Duck export { IBlackduckView,