Skip to content
Draft
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
41 changes: 0 additions & 41 deletions .devcontainer/devcontainer.json

This file was deleted.

17 changes: 17 additions & 0 deletions __tests__/fixtures/contexts/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export interface GithubContext {
context: {
repo: {
owner: string
repo: string
}
}
}

export const baseContext = (): GithubContext => ({
context: {
repo: {
owner: 'foo',
repo: 'bar'
}
}
})
32 changes: 32 additions & 0 deletions __tests__/fixtures/contexts/pull_request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { baseContext } from './base'

export const pullRequestContext = (): object => {
const base = baseContext()
return {
context: {
...base.context,
eventName: 'pull_request',
ref: 'refs/heads/main',
payload: {
action: 'closed',
number: 30,
pull_request: {
body: '[//]: # (krytenbot-project:test)\n[//]: # (krytenbot-version:0.0.1)\n\n\nThis PR was created automatically by the Krytenbot to track the next release. \nThe next version for this release is v0.0.1.\n\nYou can find the release notes for this version [here](https://github.com/foo/bar/releases).\n\n---\n\n<details>\n<summary>Krytenbot commands and options</summary>\n<br />\n\nYou can trigger Krytenbot actions by commenting on this PR:\n- `@krytenbot rebase` will rebase this PR\n- `@krytenbot recreate` will recreate this PR, overwriting any edits that have been made to it\n- `@krytenbot setversion [major|minor|patch]` will set the version for this PR\n</details>\n ',
labels: [
{
id: 7297030731,
name: 'release'
},
{
id: 7319456962,
name: 'test'
}
],
user: {
login: 'krytenbot[bot]'
}
}
}
}
}
}
63 changes: 63 additions & 0 deletions __tests__/fixtures/contexts/push.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { baseContext } from './base'

export const pushContext = (): object => {
const base = baseContext()
return {
context: {
...base.context,
eventName: 'push',
ref: 'refs/heads/main',
payload: {
after: '40e93ef1c435e7eb172ec99c4695ae675d1b87c9',
commits: [
{
author: {
email: 'test@test.com',
name: 'test',
username: 'test'
},
committer: {
email: 'test@test.com',
name: 'test',
username: 'test'
},
id: '40e93ef1c435e7eb172ec99c4695ae675d1b87c9',
message: 'test commit',
timestamp: '2024-08-12T13:56:13+01:00'
}
]
}
}
}
}

export const pushReleaseContext = (): object => {
const base = baseContext()
return {
context: {
...base.context,
eventName: 'push',
ref: 'refs/heads/main',
payload: {
after: '40e93ef1c435e7eb172ec99c4695ae675d1b87c9',
commits: [
{
author: {
email: 'krytenbot[bot]@github.com',
name: 'krytenbot[bot]',
username: 'krytenbot[bot]'
},
committer: {
email: 'krytenbot[bot]@github.com',
name: 'krytenbot[bot]',
username: 'krytenbot[bot]'
},
id: '40e93ef1c435e7eb172ec99c4695ae675d1b87c9',
message: 'test commit',
timestamp: '2024-08-12T13:56:13+01:00'
}
]
}
}
}
}
10 changes: 10 additions & 0 deletions __tests__/fixtures/mutations/createcommitonbranch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import fetchMock from 'fetch-mock'
import MockOptionsMethodPost = fetchMock.MockOptionsMethodPost
import { createCommitOnBranchMutation as mutation } from '../../../src/github-helper-queries'

export const createCommitOnBranchMutation = (options?: MockOptionsMethodPost): MockOptionsMethodPost => ({
body: { query: mutation() },
matchPartialBody: true,
overwriteRoutes: false,
...options
})
10 changes: 10 additions & 0 deletions __tests__/fixtures/mutations/createpullrequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import fetchMock from 'fetch-mock'
import MockOptionsMethodPost = fetchMock.MockOptionsMethodPost
import { createPullRequestMutation as mutation } from '../../../src/github-helper-queries'

export const createPullRequestMutation = (options?: MockOptionsMethodPost): MockOptionsMethodPost => ({
body: { query: mutation() },
matchPartialBody: true,
overwriteRoutes: false,
...options
})
10 changes: 10 additions & 0 deletions __tests__/fixtures/mutations/createref.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import fetchMock from 'fetch-mock'
import MockOptionsMethodPost = fetchMock.MockOptionsMethodPost
import { createRefMutation as mutation } from '../../../src/github-helper-queries'

export const createRefMutation = (options?: MockOptionsMethodPost): MockOptionsMethodPost => ({
body: { query: mutation() },
matchPartialBody: true,
overwriteRoutes: false,
...options
})
10 changes: 10 additions & 0 deletions __tests__/fixtures/mutations/updatepullrequestlabels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import fetchMock from 'fetch-mock'
import MockOptionsMethodPost = fetchMock.MockOptionsMethodPost
import { updatePullRequestLabelsMutation as mutation } from '../../../src/github-helper-queries'

export const updatePullRequestLabelsMutation = (options?: MockOptionsMethodPost): MockOptionsMethodPost => ({
body: { query: mutation() },
matchPartialBody: true,
overwriteRoutes: false,
...options
})
27 changes: 0 additions & 27 deletions __tests__/fixtures/push.json

This file was deleted.

10 changes: 10 additions & 0 deletions __tests__/fixtures/queries/getfilecontents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import fetchMock from 'fetch-mock'
import MockOptionsMethodPost = fetchMock.MockOptionsMethodPost
import { getFileContentQuery as query } from '../../../src/github-helper-queries'

export const getFileContents = (options?: MockOptionsMethodPost): MockOptionsMethodPost => ({
body: { query: query() },
matchPartialBody: true,
overwriteRoutes: false,
...options
})
9 changes: 9 additions & 0 deletions __tests__/fixtures/responses/createcommitonbranch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const createCommitOnBranchResponse = (): object => ({
data: {
createCommitOnBranch: {
ref: {
name: 'refs/heads/krytenbot-test'
}
}
}
})
9 changes: 9 additions & 0 deletions __tests__/fixtures/responses/createpullrequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const createPullRequestResponse = (): object => ({
data: {
createPullRequest: {
pullRequest: {
id: 1
}
}
}
})
9 changes: 9 additions & 0 deletions __tests__/fixtures/responses/createref.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const createRefResponse = (): object => ({
data: {
createRef: {
ref: {
name: 'refs/heads/krytenbot-test'
}
}
}
})
85 changes: 58 additions & 27 deletions __tests__/fixtures/responses/finddraftrelease.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
export const findDraftReleaseResponse = (): object => ({
import { KrytenbotDraftRelease } from '../../../src/github-helper'

interface KrytenbotDraftReleaseResponse {
data: {
repository: KrytenbotDraftRelease
}
}

/**
* Base response for a draft release with no branches or pull requests
*/
export const findDraftReleaseBaseResponse = (): KrytenbotDraftReleaseResponse => ({
data: {
repository: {
id: 'R_kfDOMgGsmA',
Expand All @@ -7,12 +18,7 @@ export const findDraftReleaseResponse = (): object => ({
tags: []
},
branches: {
branches: [
{
id: 'REF_kwDOMgBsmblyZWZzL2hlYWRzL2tyeXRlbmJvdC1ncmlk',
name: 'krytenbot-test'
}
]
branches: []
},
releaseLabel: {
id: 'LA_kwDOMgQsmc8AAAABsu_aSt',
Expand All @@ -23,27 +29,52 @@ export const findDraftReleaseResponse = (): object => ({
name: 'test'
},
pullRequests: {
pullRequests: [
{
id: 'PR_kwKOMgXsmc54G5lC',
number: 1,
title: 'Release `test` v0.0.1',
body: '[//]: # (krytenbot-project:test)\n[//]: # (krytenbot-version:0.0.1)\n\n\nThis PR was created automatically by the Krytenbot to track the next release. \nThe next version for this release is v0.0.1.\n\nYou can find the release notes for this version [here](https://github.com/foo/bar/releases).\n\n---\n\n<details>\n<summary>Krytenbot commands and options</summary>\n<br />\n\nYou can trigger Krytenbot actions by commenting on this PR:\n- `@krytenbot rebase` will rebase this PR\n- `@krytenbot recreate` will recreate this PR, overwriting any edits that have been made to it\n- `@krytenbot setversion [major|minor|patch]` will set the version for this PR\n</details>\n ',
createdAt: '2024-08-12T13:24:08Z',
lastEditedAt: null,
baseRefName: 'main',
baseRefOid: '40e93ef1c435e7eb172ec99c4695ae675d1b87c9',
headRefName: 'krytenbot-test',
headRefOid: '522ba908c498878c73c5aea594d8da766898bca9',
author: {
login: 'krytenbot'
},
comments: {
comments: []
}
}
]
pullRequests: []
}
}
}
})

/**
* Response for a draft release with an existing branch and pull request
*/
export const findDraftReleaseResponse = (): KrytenbotDraftReleaseResponse => {
const base = findDraftReleaseBaseResponse()
return {
data: {
repository: {
...base.data.repository,
branches: {
branches: [
{
id: 'REF_kwDOMgBsmblyZWZzL2hlYWRzL2tyeXRlbmJvdC1ncmlk',
name: 'krytenbot-test'
}
]
},
pullRequests: {
pullRequests: [
{
id: 'PR_kwKOMgXsmc54G5lC',
number: 1,
title: 'Release `test` v0.0.1',
body: '[//]: # (krytenbot-project:test)\n[//]: # (krytenbot-version:0.0.1)\n\n\nThis PR was created automatically by the Krytenbot to track the next release. \nThe next version for this release is v0.0.1.\n\nYou can find the release notes for this version [here](https://github.com/foo/bar/releases).\n\n---\n\n<details>\n<summary>Krytenbot commands and options</summary>\n<br />\n\nYou can trigger Krytenbot actions by commenting on this PR:\n- `@krytenbot rebase` will rebase this PR\n- `@krytenbot recreate` will recreate this PR, overwriting any edits that have been made to it\n- `@krytenbot setversion [major|minor|patch]` will set the version for this PR\n</details>\n ',
createdAt: '2024-08-12T13:24:08Z',
lastEditedAt: '2024-08-12T13:24:08Z',
baseRefName: 'main',
baseRefOid: '40e93ef1c435e7eb172ec99c4695ae675d1b87c9',
headRefName: 'krytenbot-test',
headRefOid: '522ba908c498878c73c5aea594d8da766898bca9',
author: {
login: 'krytenbot'
},
comments: {
comments: []
}
}
]
}
}
}
}
}
9 changes: 9 additions & 0 deletions __tests__/fixtures/responses/getfilecontents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const getFileContentsResponse = (): object => ({
data: {
repository: {
file: {
content: '{ "name": "test" "version": "0.0.1" }'
}
}
}
})
3 changes: 0 additions & 3 deletions __tests__/fixtures/responses/release.ts

This file was deleted.

Loading