Skip to content

Commit

Permalink
refactor: изменен шаблон комментариев
Browse files Browse the repository at this point in the history
  • Loading branch information
alkoleft committed Jun 4, 2024
1 parent 2485448 commit fa0d57d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 59 deletions.
66 changes: 33 additions & 33 deletions __tests__/publisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,39 @@ describe('main.ts', () => {
const publisher = new ReviewPublisher(sonar, github)
await publisher.generateReport()
})
it('publishIssues', async () => {
const sonar = new Sonar({
host: 'https://sonar.openbsl.ru',
projectKey: 'yaxunit',
branchPluginEnabled: true,
pull_number: 370
})
const github = new GithubReview({
repo: repo,
pull_number: 370,
token: token
})
const publisher = new ReviewPublisher(sonar, github)
const status = {
projectStatus: {
status: 'UNKNOWN',
ignoredConditions: false,
conditions: []
}
}
publisher.publishIssues(status, [
newIssue(
'1',
'exts/yaxunit/src/CommonModules/МокитоОбучение/Module.bsl',
3
),
newIssue(
'2',
'exts/yaxunit/src/CommonModules/МокитоОбучение/Module.bsl',
140
)
])
})
// it('publishIssues', async () => {

Check warning on line 30 in __tests__/publisher.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Some tests seem to be commented

Check warning on line 30 in __tests__/publisher.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Some tests seem to be commented
// const sonar = new Sonar({
// host: 'https://sonar.openbsl.ru',
// projectKey: 'yaxunit',
// branchPluginEnabled: true,
// pull_number: 370
// })
// const github = new GithubReview({
// repo: repo,
// pull_number: 370,
// token: token
// })
// const publisher = new ReviewPublisher(sonar, github)
// const status = {
// projectStatus: {
// status: 'UNKNOWN',
// ignoredConditions: false,
// conditions: []
// }
// }
// publisher.publishIssues(status, [
// newIssue(
// '1',
// 'exts/yaxunit/src/CommonModules/МокитоОбучение/Module.bsl',
// 3
// ),
// newIssue(
// '2',
// 'exts/yaxunit/src/CommonModules/МокитоОбучение/Module.bsl',
// 140
// )
// ])
// })
})

function newIssue(key: string, path: string, line: number) {

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

Missing return type on function

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

View workflow job for this annotation

GitHub Actions / Lint Codebase

'newIssue' is defined but never used

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

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Missing return type on function

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

View workflow job for this annotation

GitHub Actions / TypeScript Tests

'newIssue' is defined but never used
Expand Down
31 changes: 19 additions & 12 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.

16 changes: 12 additions & 4 deletions src/publisher/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class ReviewPublisher implements Publisher {
const reviewComments = await this.github.getReviewComments()

const needDelete: number[] = []
const needUpdate: { comment_id: number; comment: GitReviewParam }[] = []
const needCreate: GitReviewParam[] = []

const commentsHash = new Map(comments.map(c => [c.key, c]))
Expand All @@ -111,13 +112,13 @@ export class ReviewPublisher implements Publisher {
if (comment === undefined) {
needDelete.push(reviewComment.id)
} else if (comment.comment != reviewComment.body) {
needDelete.push(reviewComment.id)
needCreate.push(comment)
needUpdate.push({
comment_id: reviewComment.id,
comment: comment
})
}
}

await this.github.updateReview(review.id, summary)

for (const i in comments) {
const comment = comments[i]
const reviewComment = reviewCommentsHash.get(comment.key)
Expand All @@ -126,10 +127,17 @@ export class ReviewPublisher implements Publisher {
}
}

await this.github.updateReview(review.id, summary)

if (needCreate && needCreate.length) {
await this.github.createReviewComments('', needCreate)
}

for (const i in needUpdate) {
const record = needUpdate[i]
await this.github.updateReviewComment(record.comment_id, record.comment)
}

for (const i in needDelete) {
const comment_id = needDelete[i]
await this.github.deleteReviewComment(comment_id)
Expand Down
18 changes: 9 additions & 9 deletions src/sonar/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ export class SonarReport {
const rule = issue.rule
const ruleLink = `${this.host}/coding_rules?open=${rule}&rule_key=${rule}`
const issueLink = `${this.host}/project/issues?id=${issue.project}&pullRequest=${this.pull_number}&open=${issue.key}`
const tags =
issue.tags && issue.tags.length ? `\`${issue.tags.join('` `')}\`  ` : ''
const assignee = issue.assignee
? ` :bust_in_silhouette: @${issue.assignee}  `
: ''
let note = `#### [:link:](${issueLink})${issue.message}
let note = `**${issue.message}** [<sub>Why is this an issue?</sub>](${ruleLink})
${this.icon(issue.type)} ${this.capitalize(issue.type.replace('_', ''))}  ${this.icon(issue.severity)} **${this.capitalize(issue.severity)}**   :hourglass: *${issue.effort}* effort
${this.icon(issue.type)} ${this.capitalize(issue.type.replace('_', ''))}  ${this.icon(issue.severity)} **${this.capitalize(issue.severity)}**   :hourglass: *${issue.effort}* effort   [:link:](${issueLink})`
${tags}${assignee}[<sub>Why is this an issue?</sub>](${ruleLink})`

if (issue.tags && issue.tags.length) {
note += `\n\n \`${issue.tags.join('` `')}\``
}
if (issue.assignee) {
note += '   :bust_in_silhouette: @' + issue.assignee + ''
}
return note
}

Expand Down Expand Up @@ -171,7 +171,7 @@ ${this.icon(issue.type)} ${this.capitalize(issue.type.replace('_', ''))}  ${
}

const report = `# SonarQube Code Analytics
## Quality Gate ${status}
## [:link:](${this.getIssuesURL()})Quality Gate ${status}
[${this.icon(status)}](${this.getIssuesURL()})
Expand Down

0 comments on commit fa0d57d

Please sign in to comment.