Skip to content

Commit

Permalink
fix: задубливание комментариев
Browse files Browse the repository at this point in the history
  • Loading branch information
alkoleft committed Jun 4, 2024
1 parent 8880111 commit 09ea2f9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion __tests__/publisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('main.ts', () => {
})
const github = new GithubReview({
repo: repo,

Check failure on line 23 in __tests__/publisher.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand

Check failure on line 23 in __tests__/publisher.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand
pull_number: 9,
pull_number: 370,
token: token

Check failure on line 25 in __tests__/publisher.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Expected property shorthand

Check failure on line 25 in __tests__/publisher.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Expected property shorthand
})
const publisher = new ReviewPublisher(sonar, github)
Expand Down
12 changes: 8 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/github/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,18 @@ export class GithubReview {
}

async getReviewComments(): Promise<ReviewComments> {
core.debug('getReviewComments')
const response = await this.octokit.rest.pulls.listReviewComments({
...this.repo,
pull_number: this.pull_number
})

core.debug(`Response: ${JSON.stringify(response.data)}`)
return response.data
}

async deleteComment(comment_id: number) {
core.debug(`deleteComment ${comment_id}`)
await this.octokit.rest.pulls.deleteReviewComment({
...this.repo,
comment_id: comment_id
Expand Down
2 changes: 0 additions & 2 deletions src/publisher/review.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { summary } from '@actions/core'
import { GitReviewParam, GithubReview, Review, ReviewComment } from 'src/github'
import { Publisher } from 'src/model/entity'
import { Sonar } from 'src/sonar'
import * as entity from 'src/sonar/entity'

export class ReviewPublisher implements Publisher {
sonar: Sonar
Expand Down
10 changes: 5 additions & 5 deletions src/sonar/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { MetricKey, QualityStatus, SecurityLevel } from './enum'

const IMAGE_DIR_LINK = 'https://hsonar.s3.ap-southeast-1.amazonaws.com/images/'
const REVIEW_BODY_PATTERN = /^# SonarQube Code Analytics/g
const COMMENT_KEY_PATTERN =
/project\/issues\?id=.+&pullRequest=\d+&open=(.+)\)/g

export class SonarReport {
host?: string
Expand Down Expand Up @@ -256,9 +254,11 @@ ${this.duplicatedIcon(param.duplicatedValue)} ${duplicatedText}`
}

getIssueCommentKey(body: string) {
const match = COMMENT_KEY_PATTERN.exec(body)
if (match) {
return match[1]
const startSymbol = '&open='
const start = body.indexOf(startSymbol)
const end = body.indexOf(')', start)
if (start && end) {
return body.substring(start + startSymbol.length, end)
}
}
}

0 comments on commit 09ea2f9

Please sign in to comment.