generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat: multiple prs handling #132
Merged
0x4007
merged 11 commits into
ubiquity-os-marketplace:development
from
gentlementlegen:feat/multiple-prs
Oct 3, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
58d0b2c
Merge branch 'development' into feat/multiple-prs
gentlementlegen c1b1e47
chore: reopening issue on close with open pull-requests
gentlementlegen c3af93d
chore: reopening issue on close with open pull-requests
gentlementlegen df40b00
chore: reopening issue on close with open pull-requests
gentlementlegen 5f8b1c8
feat: pre-check for open pull requests
gentlementlegen b15e142
chore: changed error message for linked prs
gentlementlegen 1158a06
chore: fix cfg
gentlementlegen 94954c9
chore: fix cfg
gentlementlegen d2b998f
chore: changed defaults
gentlementlegen c230717
fix: removed regex from configuration
gentlementlegen 53933e9
Merge branch 'development' into feat/multiple-prs
gentlementlegen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { drop } from "@mswjs/data"; | ||
import { http, HttpResponse } from "msw"; | ||
import "../src/parser/command-line"; | ||
import { db } from "./__mocks__/db"; | ||
import dbSeed from "./__mocks__/db-seed.json"; | ||
import { server } from "./__mocks__/node"; | ||
|
||
const issueUrl = "https://github.com/ubiquity/work.ubq.fi/issues/69"; | ||
|
||
jest.mock("@actions/github", () => ({ | ||
context: { | ||
runId: "1", | ||
payload: { | ||
repository: { | ||
html_url: "https://github.com/ubiquibot/conversation-rewards", | ||
}, | ||
}, | ||
}, | ||
})); | ||
|
||
jest.mock("@octokit/plugin-paginate-graphql", () => ({ | ||
paginateGraphQL() { | ||
return { | ||
graphql: { | ||
paginate() { | ||
return { | ||
repository: { | ||
issue: { | ||
closedByPullRequestsReferences: { | ||
edges: [ | ||
{ | ||
node: { | ||
id: "PR_kwDOKzVPS85zXUoj", | ||
title: "fix: add state to sorting manager for bottom and top", | ||
number: 70, | ||
url: "https://github.com/ubiquity/work.ubq.fi/pull/70", | ||
state: "OPEN", | ||
author: { | ||
login: "0x4007", | ||
id: 4975670, | ||
}, | ||
repository: { | ||
owner: { | ||
login: "ubiquity", | ||
}, | ||
name: "work.ubq.fi", | ||
}, | ||
}, | ||
}, | ||
{ | ||
node: { | ||
id: "PR_kwDOKzVPS85zXUok", | ||
title: "fix: add state to sorting manager for bottom and top 2", | ||
number: 71, | ||
url: "https://github.com/ubiquity/work.ubq.fi/pull/71", | ||
state: "MERGED", | ||
author: { | ||
login: "0x4007", | ||
id: 4975670, | ||
}, | ||
repository: { | ||
owner: { | ||
login: "ubiquity", | ||
}, | ||
name: "work.ubq.fi", | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}; | ||
}, | ||
}, | ||
}; | ||
}, | ||
})); | ||
|
||
jest.mock("../src/parser/command-line", () => { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const cfg = require("./__mocks__/results/valid-configuration.json"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const dotenv = require("dotenv"); | ||
dotenv.config(); | ||
return { | ||
stateId: 1, | ||
eventName: "issues.closed", | ||
authToken: process.env.GITHUB_TOKEN, | ||
ref: "", | ||
eventPayload: { | ||
issue: { | ||
html_url: issueUrl, | ||
number: 1, | ||
state_reason: "completed", | ||
}, | ||
repository: { | ||
name: "conversation-rewards", | ||
owner: { | ||
login: "ubiquibot", | ||
id: 76412717, | ||
}, | ||
}, | ||
}, | ||
settings: JSON.stringify(cfg), | ||
}; | ||
}); | ||
|
||
beforeAll(() => server.listen()); | ||
afterEach(() => server.resetHandlers()); | ||
afterAll(() => server.close()); | ||
|
||
describe("Pre-check tests", () => { | ||
beforeEach(async () => { | ||
drop(db); | ||
for (const table of Object.keys(dbSeed)) { | ||
const tableName = table as keyof typeof dbSeed; | ||
for (const row of dbSeed[tableName]) { | ||
db[tableName].create(row); | ||
} | ||
} | ||
}); | ||
|
||
it("Should reopen the issue and not generate rewards if linked pull-requests are still open", async () => { | ||
const patchMock = jest.fn(() => HttpResponse.json({})); | ||
server.use(http.patch("https://api.github.com/repos/ubiquity/work.ubq.fi/issues/69", patchMock, { once: true })); | ||
const module = (await import("../src/index")) as unknown as { default: Promise<string> }; | ||
const result = await module.default; | ||
expect(result).toEqual("All linked pull requests must be closed to generate rewards."); | ||
expect(patchMock).toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought our logger abstracts all this away. Why not just add a param
postComment: boolean
in the logger methods? I'm pretty sure I implemented that the first go around. It was the third parameter I believe.(
message: string, metadata: Record<key, value>, postComment: boolean
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we wanted to separate Supabase from the logger for a few reasons:
My suggestion was to have optional packages that you can add on init, like Octokit does if you want to use pagination for example, where we could link a package that would post comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can file a spec before it's forgotten about
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a task carried out about this I remember, let me find it.
ubiquity-os/ubiquity-os-logger#35