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

Prepare for v12 - and remove the user check in github #1435

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@
## Main

<!-- Your comment below this -->
<!-- Your comment above this -->

## 12.0.0

Bumping to 12.x because we've raised the minimum to node version from 14 to 18. This is due to some of our dependencies
requiring a newer version of node. This is a breaking change for some folk! Also, 14 has been out of support for quite a while
now and Node 18 gives us a full year. - [@orta]

- Remove the user checks in GitHub comment/inline comment lookups, to allow using app tokens [#1433] - [@orta]
- Upgrade `node` engine from `>=14.13.1` to `>=18` [@heltoft]
- Upgrade `@types/node` from `^10.11.3` to `18.19.18` [@heltoft]
- GitLab: [#1386] Move from `@gitbeaker/node` to `@gitbeaker/rest` [@heltoft]
- GitLab: [#1412] Danger fails to create inline comments on Gitlab [@heltoft]
- GitLab: [#1405] Can't post multiple inline comments [@heltoft]
- GitLab: Do not delete system resolved danger inline comments [@heltoft]
<!-- Your comment above this -->


## 11.3.1

Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"name": "danger",
"version": "11.3.1",
"version": "12.0.0",
"description": "Unit tests for Team Culture",
"main": "distribution/danger.js",
"typings": "distribution/danger.d.ts",
"bin": {
"danger": "distribution/commands/danger.js",
"danger-js": "distribution/commands/danger.js",
"danger-pr": "distribution/commands/danger-pr.js",
"danger-runner": "distribution/commands/danger-runner.js",
"danger-process": "distribution/commands/danger-process.js",
"danger-ci": "distribution/commands/danger-ci.js",
"danger-init": "distribution/commands/danger-init.js",
"danger-js": "distribution/commands/danger.js",
"danger-local": "distribution/commands/danger-local.js",
"danger-reset-status": "distribution/commands/danger-reset-status.js"
"danger-pr": "distribution/commands/danger-pr.js",
"danger-process": "distribution/commands/danger-process.js",
"danger-reset-status": "distribution/commands/danger-reset-status.js",
"danger-runner": "distribution/commands/danger-runner.js"
},
"jest": {
"preset": "ts-jest",
Expand Down Expand Up @@ -77,6 +77,7 @@
"type": "git",
"url": "git+https://github.com/danger/danger-js.git"
},
"packageManager": "[email protected]",
"keywords": [
"danger",
"ci"
Expand Down Expand Up @@ -142,6 +143,7 @@
"typescript-json-schema": "^0.53.0"
},
"dependencies": {
"@gitbeaker/rest": "^38.0.0",
"@octokit/rest": "^18.12.0",
"async-retry": "1.2.3",
"chalk": "^2.3.0",
Expand All @@ -150,7 +152,6 @@
"debug": "^4.1.1",
"fast-json-patch": "^3.0.0-1",
"get-stdin": "^6.0.0",
"@gitbeaker/rest": "^38.0.0",
"http-proxy-agent": "^5.0.0",
"https-proxy-agent": "^5.0.1",
"hyperlinker": "^1.0.0",
Expand Down Expand Up @@ -180,7 +181,6 @@
"require-from-string": "^2.0.2",
"supports-hyperlinks": "^1.0.1"
},
"optionalDependencies": {},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
Expand Down
9 changes: 3 additions & 6 deletions source/platforms/github/GitHubAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,11 @@ export class GitHubAPI {
// The above is the API for Platform

getDangerCommentIDs = async (dangerID: string): Promise<string[]> => {
const userID = await this.getUserID()
const allComments = await this.getPullRequestComments()
const dangerIDMessage = dangerIDToString(dangerID)
this.d(`User ID: ${userID}`)
this.d(`Looking at ${allComments.length} comments for ${dangerIDMessage}`)
return allComments
.filter((comment) => comment.body.includes(dangerIDMessage)) // does it contain the right danger ID?
.filter((comment) => comment.user.id === userID) // Does it have the right user ID?
.filter((comment) => comment.body.includes("Generated by")) // Does it look like a danger message?
.map((comment) => comment.id) // only return IDs
}
Expand Down Expand Up @@ -318,15 +315,15 @@ export class GitHubAPI {
getPullRequestInlineComments = async (
dangerID: string
): Promise<(GitHubIssueComment & { ownedByDanger: boolean })[]> => {
const userID = await this.getUserID()
const repo = this.repoMetadata.repoSlug
const prID = this.repoMetadata.pullRequestID
const dangerIDMessage = dangerIDToString(dangerID)
return await this.getAllOfResource(`repos/${repo}/pulls/${prID}/comments`).then((v: GitHubIssueComment[]) => {
return v
.filter(Boolean)
.filter((i) => !!i)
.map((i) => {
return { ...i, ownedByDanger: i.user.id == userID && i.body.includes(dangerIDMessage) }
// Can't use && i.body.includes("Generated by") because it's not there on an inline comment
return { ...i, ownedByDanger: i.body.includes(dangerIDMessage) }
})
.filter((i) => i.ownedByDanger)
})
Expand Down
8 changes: 3 additions & 5 deletions source/platforms/github/_tests/_github_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,19 @@ describe("API testing", () => {
expect(commentIDs.length).toEqual(0)
})

it("getPullRequestInlineComment gets only comments for given DangerId", async () => {
it("getPullRequestInlineComment gets only comments for given dangerID", async () => {
api.getAllOfResource = await requestWithFixturedJSON("github_inline_comments_with_danger.json")
api.getUserID = () => new Promise<number>((r) => r(20229914))

const comments = await api.getPullRequestInlineComments("default")

expect(comments.length).toEqual(1)
expect(comments[0].ownedByDanger).toBeTruthy()
})

it("getPullRequestInlineComment doesn't get comments as the DangerId is different", async () => {
it("getPullRequestInlineComment doesn't get comments as the dangerID is different", async () => {
api.getAllOfResource = await requestWithFixturedJSON("github_inline_comments_with_danger.json")
api.getUserID = () => new Promise<number>((r) => r(123))

const comments = await api.getPullRequestInlineComments("default")
const comments = await api.getPullRequestInlineComments("other-danger-id")

expect(comments.length).toEqual(0)
})
Expand Down