Skip to content

Commit

Permalink
feat: add Octokit dependency and update test configurations
Browse files Browse the repository at this point in the history
Add @octokit/rest dependency and update test setups for command execution.
  • Loading branch information
gentlementlegen committed Oct 14, 2024
1 parent cc0ee1e commit d86eade
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 15 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"open-source"
],
"dependencies": {
"@octokit/rest": "^20.1.0",
"@sinclair/typebox": "0.32.30",
"@supabase/supabase-js": "2.43.2",
"@ubiquity-os/ubiquity-os-kernel": "^2.2.0",
Expand Down
13 changes: 11 additions & 2 deletions tests/__mocks__/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ import { http, HttpResponse } from "msw";
* Intercepts the routes and returns a custom payload
*/
export const handlers = [
http.get("https://api.github.com/users/:user", () => {
return HttpResponse.json();
http.get("https://api.github.com/users/:user", (req) => {
const { user } = req.params;

const mockedUserData = {
login: user,
id: 1,
url: `https://api.github.com/users/${user}`,
type: "User",
};

return HttpResponse.json(mockedUserData);
}),
http.post("https://api.github.com/repos/:org/:repo/issues/:id/comments", () => {
return HttpResponse.json();
Expand Down
2 changes: 1 addition & 1 deletion tests/http/request.http
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Content-Type: application/json
"stateId": "",
"eventName": "issue_comment.created",
"eventPayload": "{\"action\":\"created\",\"issue\":{\"url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/issues/{{issue_number}}\",\"repository_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}\",\"labels_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/issues/{{issue_number}}/labels{/name}\",\"comments_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/issues/{{issue_number}}/comments\",\"events_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/issues/{{issue_number}}/events\",\"html_url\":\"https://github.com/{{org_name}}/{{repo_name}}/issues/{{issue_number}}\",\"id\":2297627819,\"node_id\":\"I_kwDOLy-Pv86I8wSr\",\"number\":5,\"title\":\"New issue\",\"user\":{\"login\":\"ubiquibot\",\"id\":1,\"node_id\":\"MDQ6VXNlcjk4MDcwMDg=\",\"avatar_url\":\"https://avatars.githubusercontent.com/u/1?v=4\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/ubiquibot\",\"html_url\":\"https://github.com/ubiquibot\",\"followers_url\":\"https://api.github.com/users/ubiquibot/followers\",\"following_url\":\"https://api.github.com/users/ubiquibot/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/ubiquibot/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/ubiquibot/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/ubiquibot/subscriptions\",\"organizations_url\":\"https://api.github.com/users/ubiquibot/orgs\",\"repos_url\":\"https://api.github.com/users/ubiquibot/repos\",\"events_url\":\"https://api.github.com/users/ubiquibot/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/ubiquibot/received_events\",\"type\":\"User\",\"site_admin\":false},\"labels\":[],\"state\":\"open\",\"locked\":false,\"assignee\":null,\"assignees\":[],\"milestone\":null,\"comments\":34,\"created_at\":\"2024-05-15T11:22:48Z\",\"updated_at\":\"2024-05-19T11:54:24Z\",\"closed_at\":null,\"author_association\":\"CONTRIBUTOR\",\"active_lock_reason\":null,\"body\":\"Another issue.\",\"reactions\":{\"url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/issues/{{issue_number}}/reactions\",\"total_count\":0,\"+1\":0,\"-1\":0,\"laugh\":0,\"hooray\":0,\"confused\":0,\"heart\":0,\"rocket\":0,\"eyes\":0},\"timeline_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/issues/{{issue_number}}/timeline\",\"performed_via_github_app\":null,\"state_reason\":null},\"comment\":{\"url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/issues/comments/1\",\"html_url\":\"https://github.com/{{org_name}}/{{repo_name}}/issues/{{issue_number}}#issuecomment-1\",\"issue_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/issues/{{issue_number}}\",\"id\":1,\"node_id\":\"IC_kwDOLy-Pv85-UI-X\",\"user\":{\"login\":\"ubiquibot\",\"id\":1,\"node_id\":\"MDQ6VXNlcjk4MDcwMDg=\",\"avatar_url\":\"https://avatars.githubusercontent.com/u/1?v=4\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/ubiquibot\",\"html_url\":\"https://github.com/ubiquibot\",\"followers_url\":\"https://api.github.com/users/ubiquibot/followers\",\"following_url\":\"https://api.github.com/users/ubiquibot/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/ubiquibot/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/ubiquibot/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/ubiquibot/subscriptions\",\"organizations_url\":\"https://api.github.com/users/ubiquibot/orgs\",\"repos_url\":\"https://api.github.com/users/ubiquibot/repos\",\"events_url\":\"https://api.github.com/users/ubiquibot/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/ubiquibot/received_events\",\"type\":\"User\",\"site_admin\":false},\"created_at\":\"2024-05-19T11:54:23Z\",\"updated_at\":\"2024-05-19T11:54:23Z\",\"author_association\":\"CONTRIBUTOR\",\"body\":\"{{command}}\",\"reactions\":{\"url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/issues/comments/1/reactions\",\"total_count\":0,\"+1\":0,\"-1\":0,\"laugh\":0,\"hooray\":0,\"confused\":0,\"heart\":0,\"rocket\":0,\"eyes\":0},\"performed_via_github_app\":null},\"repository\":{\"id\":1,\"node_id\":\"R_kgDOLy-Pvw\",\"name\":\"{{repo_name}}\",\"full_name\":\"{{org_name}}/{{repo_name}}\",\"private\":false,\"owner\":{\"login\":\"{{org_name}}\",\"id\":1,\"node_id\":\"O_kgDOCYfonA\",\"avatar_url\":\"https://avatars.githubusercontent.com/u/1?v=4\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/{{org_name}}\",\"html_url\":\"https://github.com/{{org_name}}\",\"followers_url\":\"https://api.github.com/users/{{org_name}}/followers\",\"following_url\":\"https://api.github.com/users/{{org_name}}/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/{{org_name}}/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/{{org_name}}/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/{{org_name}}/subscriptions\",\"organizations_url\":\"https://api.github.com/users/{{org_name}}/orgs\",\"repos_url\":\"https://api.github.com/users/{{org_name}}/repos\",\"events_url\":\"https://api.github.com/users/{{org_name}}/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/{{org_name}}/received_events\",\"type\":\"Organization\",\"site_admin\":false},\"html_url\":\"https://github.com/{{org_name}}/{{repo_name}}\",\"description\":null,\"fork\":false,\"url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}\",\"forks_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/forks\",\"keys_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/keys{/key_id}\",\"collaborators_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/collaborators{/collaborator}\",\"teams_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/teams\",\"hooks_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/hooks\",\"issue_events_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/issues/events{/number}\",\"events_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/events\",\"assignees_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/assignees{/user}\",\"branches_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/branches{/branch}\",\"tags_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/tags\",\"blobs_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/git/blobs{/sha}\",\"git_tags_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/git/tags{/sha}\",\"git_refs_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/git/refs{/sha}\",\"trees_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/git/trees{/sha}\",\"statuses_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/statuses/{sha}\",\"languages_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/languages\",\"stargazers_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/stargazers\",\"contributors_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/contributors\",\"subscribers_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/subscribers\",\"subscription_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/subscription\",\"commits_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/commits{/sha}\",\"git_commits_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/git/commits{/sha}\",\"comments_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/comments{/number}\",\"issue_comment_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/issues/comments{/number}\",\"contents_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/contents/{+path}\",\"compare_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/compare/{base}...{head}\",\"merges_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/merges\",\"archive_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/{archive_format}{/ref}\",\"downloads_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/downloads\",\"issues_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/issues{/number}\",\"pulls_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/pulls{/number}\",\"milestones_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/milestones{/number}\",\"notifications_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/notifications{?since,all,participating}\",\"labels_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/labels{/name}\",\"releases_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/releases{/id}\",\"deployments_url\":\"https://api.github.com/repos/{{org_name}}/{{repo_name}}/deployments\",\"created_at\":\"2024-04-25T05:19:30Z\",\"updated_at\":\"2024-05-19T09:47:02Z\",\"pushed_at\":\"2024-05-19T09:46:59Z\",\"git_url\":\"git://github.com/{{org_name}}/{{repo_name}}.git\",\"ssh_url\":\"[email protected]:{{org_name}}/{{repo_name}}.git\",\"clone_url\":\"https://github.com/{{org_name}}/{{repo_name}}.git\",\"svn_url\":\"https://github.com/{{org_name}}/{{repo_name}}\",\"homepage\":null,\"size\":56,\"stargazers_count\":0,\"watchers_count\":0,\"language\":null,\"has_issues\":true,\"has_projects\":true,\"has_downloads\":true,\"has_wiki\":false,\"has_pages\":false,\"has_discussions\":false,\"forks_count\":0,\"mirror_url\":null,\"archived\":false,\"disabled\":false,\"open_issues_count\":1,\"license\":null,\"allow_forking\":true,\"is_template\":false,\"web_commit_signoff_required\":false,\"topics\":[],\"visibility\":\"public\",\"forks\":0,\"open_issues\":1,\"watchers\":0,\"default_branch\":\"main\",\"custom_properties\":{}},\"organization\":{\"login\":\"{{org_name}}\",\"id\":1,\"node_id\":\"O_kgDOCYfonA\",\"url\":\"https://api.github.com/orgs/{{org_name}}\",\"repos_url\":\"https://api.github.com/orgs/{{org_name}}/repos\",\"events_url\":\"https://api.github.com/orgs/{{org_name}}/events\",\"hooks_url\":\"https://api.github.com/orgs/{{org_name}}/hooks\",\"issues_url\":\"https://api.github.com/orgs/{{org_name}}/issues\",\"members_url\":\"https://api.github.com/orgs/{{org_name}}/members{/member}\",\"public_members_url\":\"https://api.github.com/orgs/{{org_name}}/public_members{/member}\",\"avatar_url\":\"https://avatars.githubusercontent.com/u/1?v=4\",\"description\":null},\"sender\":{\"login\":\"ubiquibot\",\"id\":1,\"node_id\":\"MDQ6VXNlcjk4MDcwMDg=\",\"avatar_url\":\"https://avatars.githubusercontent.com/u/1?v=4\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/ubiquibot\",\"html_url\":\"https://github.com/ubiquibot\",\"followers_url\":\"https://api.github.com/users/ubiquibot/followers\",\"following_url\":\"https://api.github.com/users/ubiquibot/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/ubiquibot/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/ubiquibot/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/ubiquibot/subscriptions\",\"organizations_url\":\"https://api.github.com/users/ubiquibot/orgs\",\"repos_url\":\"https://api.github.com/users/ubiquibot/repos\",\"events_url\":\"https://api.github.com/users/ubiquibot/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/ubiquibot/received_events\",\"type\":\"User\",\"site_admin\":false},\"installation\":{\"id\":1,\"node_id\":\"MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uNDgzODE5NzI=\"}}",
"settings": "{\"testing\":true}",
"settings": {},
"ref": "",
"authToken": "{{token}}"
}
33 changes: 22 additions & 11 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { afterAll, afterEach, beforeAll, beforeEach, describe, it } from "@jest/globals";
import { drop } from "@mswjs/data";
import { Octokit } from "@octokit/rest";
import { createClient } from "@supabase/supabase-js";
import { Logs } from "@ubiquity-os/ubiquity-os-logger";
import { createAdapters } from "../src/adapters";
import { run } from "../src/run";
import { CommandContext } from "../src/types/context";
import { Database } from "../src/types/database";
import { db } from "./__mocks__/db";
import { server } from "./__mocks__/node";
import commentCreatedPayload from "./__mocks__/payloads/comment-created.json";
Expand Down Expand Up @@ -62,17 +67,23 @@ describe("User tests", () => {
});

it("Should run the command", async () => {
expect(
async () =>
await run({
eventName: event,
ref: "",
authToken: "",
stateId: "",
settings: { allowPublicQuery: true },
eventPayload: commentCreatedPayload,
} as unknown as CommandContext)
).not.toThrow();
const context = {
eventName: event,
ref: "",
authToken: "",
stateId: "",
config: { allowPublicQuery: true },
payload: commentCreatedPayload,
logger: new Logs("debug"),
adapters: {},
env: {
SUPABASE_URL: "",
SUPABASE_KEY: "",
},
octokit: new Octokit(),
} as unknown as CommandContext;
context.adapters = createAdapters(createClient<Database>(context.env.SUPABASE_URL, context.env.SUPABASE_KEY), context);
expect(async () => await run(context)).not.toThrow();
});

it("Should ignore invalid command", async () => {
Expand Down
31 changes: 30 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@
before-after-hook "^3.0.2"
universal-user-agent "^7.0.0"

"@octokit/core@^5.0.1":
"@octokit/core@^5.0.1", "@octokit/core@^5.0.2":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@octokit/core/-/core-5.2.0.tgz#ddbeaefc6b44a39834e1bb2e58a49a117672a7ea"
integrity sha512-1LFfa/qnMQvEOAdzlQymH0ulepxbxnCYAKJZfMci/5XJyIHWgEYnDmgnKakbTh7CH2tFQ5O60oYDvns4i9RAIg==
Expand Down Expand Up @@ -1639,6 +1639,13 @@
resolved "https://registry.yarnpkg.com/@octokit/openapi-webhooks-types/-/openapi-webhooks-types-8.3.0.tgz#a7a4da00c0f27f7f5708eb3fcebefa08f8d51125"
integrity sha512-vKLsoR4xQxg4Z+6rU/F65ItTUz/EXbD+j/d4mlq2GW8TsA4Tc8Kdma2JTAAJ5hrKWUQzkR/Esn2fjsqiVRYaQg==

"@octokit/[email protected]":
version "11.3.1"
resolved "https://registry.yarnpkg.com/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-11.3.1.tgz#fe92d04b49f134165d6fbb716e765c2f313ad364"
integrity sha512-ryqobs26cLtM1kQxqeZui4v8FeznirUsksiA+RYemMPJ7Micju0WSkv50dBksTuZks9O5cg4wp+t8fZ/cLY56g==
dependencies:
"@octokit/types" "^13.5.0"

"@octokit/[email protected]":
version "11.3.3"
resolved "https://registry.yarnpkg.com/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-11.3.3.tgz#efc97ba66aae6797e2807a082f99b9cfc0e05aba"
Expand All @@ -1653,6 +1660,18 @@
dependencies:
"@octokit/types" "^12.6.0"

"@octokit/plugin-request-log@^4.0.0":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@octokit/plugin-request-log/-/plugin-request-log-4.0.1.tgz#98a3ca96e0b107380664708111864cb96551f958"
integrity sha512-GihNqNpGHorUrO7Qa9JbAl0dbLnqJVrV8OXe2Zm5/Y4wFkZQDfTreBzVmiRfJVfE4mClXdihHnbpyyO9FSX4HA==

"@octokit/[email protected]":
version "13.2.2"
resolved "https://registry.yarnpkg.com/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-13.2.2.tgz#af8e5dd2cddfea576f92ffaf9cb84659f302a638"
integrity sha512-EI7kXWidkt3Xlok5uN43suK99VWqc8OaIMktY9d9+RNKl69juoTyxmLoWPIZgJYzi41qj/9zU7G/ljnNOJ5AFA==
dependencies:
"@octokit/types" "^13.5.0"

"@octokit/[email protected]":
version "13.2.4"
resolved "https://registry.yarnpkg.com/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-13.2.4.tgz#543add032d3fe3f5d2839bfd619cf66d85469f01"
Expand Down Expand Up @@ -1720,6 +1739,16 @@
"@octokit/types" "^13.1.0"
universal-user-agent "^7.0.2"

"@octokit/rest@^20.1.0":
version "20.1.1"
resolved "https://registry.yarnpkg.com/@octokit/rest/-/rest-20.1.1.tgz#ec775864f53fb42037a954b9a40d4f5275b3dc95"
integrity sha512-MB4AYDsM5jhIHro/dq4ix1iWTLGToIGk6cWF5L6vanFaMble5jTX/UBQyiv05HsWnwUtY8JrfHy2LWfKwihqMw==
dependencies:
"@octokit/core" "^5.0.2"
"@octokit/plugin-paginate-rest" "11.3.1"
"@octokit/plugin-request-log" "^4.0.0"
"@octokit/plugin-rest-endpoint-methods" "13.2.2"

"@octokit/[email protected]":
version "13.5.0"
resolved "https://registry.yarnpkg.com/@octokit/types/-/types-13.5.0.tgz#4796e56b7b267ebc7c921dcec262b3d5bfb18883"
Expand Down

0 comments on commit d86eade

Please sign in to comment.