Skip to content

Commit

Permalink
fix: actually update pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Jun 28, 2022
1 parent 60031a8 commit d57878f
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 174 deletions.
11 changes: 10 additions & 1 deletion src/compose-create-pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,16 @@ export async function composeCreatePullRequest(
);
}

if (!branchExists) {
if (branchExists) {
// https://docs.github.com/en/rest/git/refs#update-a-reference
await octokit.request("PATCH /repos/{owner}/{repo}/git/refs/{ref}", {
owner: state.fork,
repo,
sha: state.latestCommitSha,
ref: `heads/${head}`,
force: true,
});
} else {
// https://developer.github.com/v3/git/refs/#create-a-reference
await octokit.request("POST /repos/{owner}/{repo}/git/refs", {
owner: state.fork,
Expand Down
168 changes: 117 additions & 51 deletions test/fixtures/update-existing-pull-request.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"content-encoding": "gzip",
"content-security-policy": "default-src 'none'",
"content-type": "application/json; charset=utf-8",
"date": "Tue, 28 Jun 2022 00:56:38 GMT",
"date": "Tue, 28 Jun 2022 10:54:27 GMT",
"etag": "W/\"d1c1b3565de23378611062c9f75ae3ab70e1a8319ad2d63bee6d113b7c03462a\"",
"github-authentication-token-expiration": "2022-08-24 23:46:54 UTC",
"last-modified": "Thu, 15 Oct 2020 00:04:09 GMT",
Expand All @@ -42,13 +42,13 @@
"x-github-api-version-selected": "",
"x-github-api-version-selected-reason": "unavailable",
"x-github-media-type": "github.v3; format=json",
"x-github-request-id": "DE53:8292:16513E:1C0B03:62BA51C6",
"x-github-request-id": "DA5E:487E:516208:574BAF:62BADDE3",
"x-oauth-scopes": "notifications, repo, workflow, write:org",
"x-ratelimit-limit": "5000",
"x-ratelimit-remaining": "4834",
"x-ratelimit-reset": "1656378677",
"x-ratelimit-remaining": "4981",
"x-ratelimit-reset": "1656414682",
"x-ratelimit-resource": "core",
"x-ratelimit-used": "166",
"x-ratelimit-used": "19",
"x-xss-protection": "0"
},
"data": {
Expand Down Expand Up @@ -198,7 +198,7 @@
"content-encoding": "gzip",
"content-security-policy": "default-src 'none'",
"content-type": "application/json; charset=utf-8",
"date": "Tue, 28 Jun 2022 00:56:39 GMT",
"date": "Tue, 28 Jun 2022 10:54:27 GMT",
"etag": "W/\"2fe2b7c39b2b80f77c8d03c07249ea7ce2e2135086205c5d4afe82ca68ce490e\"",
"github-authentication-token-expiration": "2022-08-24 23:46:54 UTC",
"last-modified": "Thu, 15 Oct 2020 00:04:06 GMT",
Expand All @@ -214,13 +214,13 @@
"x-github-api-version-selected": "",
"x-github-api-version-selected-reason": "unavailable",
"x-github-media-type": "github.v3; format=json",
"x-github-request-id": "DE5A:655E:82AA0C:8F5992:62BA51C7",
"x-github-request-id": "DA61:487C:2169A7:266613:62BADDE3",
"x-oauth-scopes": "notifications, repo, workflow, write:org",
"x-ratelimit-limit": "5000",
"x-ratelimit-remaining": "4833",
"x-ratelimit-reset": "1656378677",
"x-ratelimit-remaining": "4980",
"x-ratelimit-reset": "1656414682",
"x-ratelimit-resource": "core",
"x-ratelimit-used": "167",
"x-ratelimit-used": "20",
"x-xss-protection": "0"
},
"data": [
Expand Down Expand Up @@ -342,7 +342,7 @@
"content-length": "1497",
"content-security-policy": "default-src 'none'",
"content-type": "application/json; charset=utf-8",
"date": "Tue, 28 Jun 2022 00:56:39 GMT",
"date": "Tue, 28 Jun 2022 10:54:28 GMT",
"etag": "\"d03f90789027d35f4bd7d29532ef91a3ef2712f9f1227c7a7ade3bab52d506b7\"",
"github-authentication-token-expiration": "2022-08-24 23:46:54 UTC",
"location": "https://api.github.com/repos/gr2m/pull-request-test/git/trees/6861387e75d70633a21b9697663143ccb889f7b9",
Expand All @@ -356,13 +356,13 @@
"x-github-api-version-selected": "",
"x-github-api-version-selected-reason": "unavailable",
"x-github-media-type": "github.v3; format=json",
"x-github-request-id": "DE5B:6352:11F8233:12EE42B:62BA51C7",
"x-github-request-id": "DA64:2D39:36EDA9:3C3B73:62BADDE3",
"x-oauth-scopes": "notifications, repo, workflow, write:org",
"x-ratelimit-limit": "5000",
"x-ratelimit-remaining": "4832",
"x-ratelimit-reset": "1656378677",
"x-ratelimit-remaining": "4979",
"x-ratelimit-reset": "1656414682",
"x-ratelimit-resource": "core",
"x-ratelimit-used": "168",
"x-ratelimit-used": "21",
"x-xss-protection": "0"
},
"data": {
Expand Down Expand Up @@ -451,10 +451,10 @@
"content-length": "1125",
"content-security-policy": "default-src 'none'",
"content-type": "application/json; charset=utf-8",
"date": "Tue, 28 Jun 2022 00:56:40 GMT",
"etag": "\"564ec8425d11abba8649d6ea52c4c48d7569ccdf04ef525f1b46aab3aa25b9d7\"",
"date": "Tue, 28 Jun 2022 10:54:28 GMT",
"etag": "\"c78d461e061e0a0706df447aadba22862b83d2601145d4859365c4b9cde53877\"",
"github-authentication-token-expiration": "2022-08-24 23:46:54 UTC",
"location": "https://api.github.com/repos/gr2m/pull-request-test/git/commits/2bb54d86e7b0f06c24caed3034b920cad2d04990",
"location": "https://api.github.com/repos/gr2m/pull-request-test/git/commits/e4346a61815d43fa49531e0be9f6dd7d5c9a0ba7",
"referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"server": "GitHub.com",
"strict-transport-security": "max-age=31536000; includeSubdomains; preload",
Expand All @@ -465,29 +465,29 @@
"x-github-api-version-selected": "",
"x-github-api-version-selected-reason": "unavailable",
"x-github-media-type": "github.v3; format=json",
"x-github-request-id": "DE5E:48C7:6FD77A:7C86B0:62BA51C7",
"x-github-request-id": "DA67:3020:1597856:16C2DF8:62BADDE4",
"x-oauth-scopes": "notifications, repo, workflow, write:org",
"x-ratelimit-limit": "5000",
"x-ratelimit-remaining": "4831",
"x-ratelimit-reset": "1656378677",
"x-ratelimit-remaining": "4978",
"x-ratelimit-reset": "1656414682",
"x-ratelimit-resource": "core",
"x-ratelimit-used": "169",
"x-ratelimit-used": "22",
"x-xss-protection": "0"
},
"data": {
"sha": "2bb54d86e7b0f06c24caed3034b920cad2d04990",
"node_id": "C_kwDOCZh5ZNoAKDJiYjU0ZDg2ZTdiMGYwNmMyNGNhZWQzMDM0YjkyMGNhZDJkMDQ5OTA",
"url": "https://api.github.com/repos/gr2m/pull-request-test/git/commits/2bb54d86e7b0f06c24caed3034b920cad2d04990",
"html_url": "https://github.com/gr2m/pull-request-test/commit/2bb54d86e7b0f06c24caed3034b920cad2d04990",
"sha": "e4346a61815d43fa49531e0be9f6dd7d5c9a0ba7",
"node_id": "C_kwDOCZh5ZNoAKGU0MzQ2YTYxODE1ZDQzZmE0OTUzMWUwYmU5ZjZkZDdkNWM5YTBiYTc",
"url": "https://api.github.com/repos/gr2m/pull-request-test/git/commits/e4346a61815d43fa49531e0be9f6dd7d5c9a0ba7",
"html_url": "https://github.com/gr2m/pull-request-test/commit/e4346a61815d43fa49531e0be9f6dd7d5c9a0ba7",
"author": {
"name": "Gregor Martynus",
"email": "39992+gr2m@users.noreply.github.com",
"date": "2022-06-28T00:56:40Z"
"date": "2022-06-28T10:54:28Z"
},
"committer": {
"name": "Gregor Martynus",
"email": "39992+gr2m@users.noreply.github.com",
"date": "2022-06-28T00:56:40Z"
"date": "2022-06-28T10:54:28Z"
},
"tree": {
"sha": "6861387e75d70633a21b9697663143ccb889f7b9",
Expand Down Expand Up @@ -539,7 +539,7 @@
"content-encoding": "gzip",
"content-security-policy": "default-src 'none'",
"content-type": "application/json; charset=utf-8",
"date": "Tue, 28 Jun 2022 00:56:40 GMT",
"date": "Tue, 28 Jun 2022 10:54:28 GMT",
"etag": "W/\"59f77d120f600b4abc9075ad4e0e7ca9e0c6941f1feec46a52b0458b9903b8ee\"",
"github-authentication-token-expiration": "2022-08-24 23:46:54 UTC",
"last-modified": "Thu, 15 Oct 2020 00:04:09 GMT",
Expand All @@ -554,14 +554,14 @@
"x-github-api-version-selected": "",
"x-github-api-version-selected-reason": "unavailable",
"x-github-media-type": "github.v3; format=json",
"x-github-request-id": "DE62:2D3E:1239478:12BEEA8:62BA51C8",
"x-github-request-id": "DA6A:7767:13DFDB4:15072D3:62BADDE4",
"x-oauth-scopes": "notifications, repo, workflow, write:org",
"x-poll-interval": "300",
"x-ratelimit-limit": "5000",
"x-ratelimit-remaining": "4830",
"x-ratelimit-reset": "1656378677",
"x-ratelimit-remaining": "4977",
"x-ratelimit-reset": "1656414682",
"x-ratelimit-resource": "core",
"x-ratelimit-used": "170",
"x-ratelimit-used": "23",
"x-xss-protection": "0"
},
"data": {
Expand Down Expand Up @@ -603,7 +603,7 @@
"content-encoding": "gzip",
"content-security-policy": "default-src 'none'",
"content-type": "application/json; charset=utf-8",
"date": "Tue, 28 Jun 2022 00:56:41 GMT",
"date": "Tue, 28 Jun 2022 10:54:29 GMT",
"github-authentication-token-expiration": "2022-08-24 23:46:54 UTC",
"referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"server": "GitHub.com",
Expand All @@ -616,13 +616,13 @@
"x-github-api-version-selected": "",
"x-github-api-version-selected-reason": "unavailable",
"x-github-media-type": "github.v3; format=json",
"x-github-request-id": "DE65:6E3A:ED6A06:FCAAB1:62BA51C8",
"x-github-request-id": "DA6D:301F:D8BB51:E974CA:62BADDE5",
"x-oauth-scopes": "notifications, repo, workflow, write:org",
"x-ratelimit-limit": "30",
"x-ratelimit-remaining": "28",
"x-ratelimit-reset": "1656377838",
"x-ratelimit-remaining": "29",
"x-ratelimit-reset": "1656413729",
"x-ratelimit-resource": "search",
"x-ratelimit-used": "2",
"x-ratelimit-used": "1",
"x-xss-protection": "0"
},
"data": {
Expand Down Expand Up @@ -702,6 +702,72 @@
}
}
},
{
"request": {
"method": "PATCH",
"baseUrl": "https://api.github.com",
"headers": {
"accept": "application/vnd.github.v3+json",
"user-agent": "octokit-core.js/3.2.5 Node.js/18.3.0 (darwin; arm64)"
},
"mediaType": {
"format": "",
"previews": []
},
"request": {},
"url": "/repos/{owner}/{repo}/git/refs/{ref}",
"owner": "gr2m",
"repo": "pull-request-test",
"sha": "e4346a61815d43fa49531e0be9f6dd7d5c9a0ba7",
"ref": "heads/update-existing-pull-request",
"force": true
},
"response": {
"status": 200,
"url": "https://api.github.com/repos/gr2m/pull-request-test/git/refs/heads%2Fupdate-existing-pull-request",
"headers": {
"access-control-allow-origin": "*",
"access-control-expose-headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
"cache-control": "private, max-age=60, s-maxage=60",
"connection": "close",
"content-encoding": "gzip",
"content-security-policy": "default-src 'none'",
"content-type": "application/json; charset=utf-8",
"date": "Tue, 28 Jun 2022 10:54:30 GMT",
"etag": "W/\"052e1471d5efe762b6d218d0f0644afc50ed85d0eb9d97592fbfdd3cffb62876\"",
"github-authentication-token-expiration": "2022-08-24 23:46:54 UTC",
"referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"server": "GitHub.com",
"strict-transport-security": "max-age=31536000; includeSubdomains; preload",
"transfer-encoding": "chunked",
"vary": "Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With",
"x-accepted-oauth-scopes": "repo",
"x-content-type-options": "nosniff",
"x-frame-options": "deny",
"x-github-api-version-selected": "",
"x-github-api-version-selected-reason": "unavailable",
"x-github-media-type": "github.v3; format=json",
"x-github-request-id": "DA6E:8296:C25F39:CD8F17:62BADDE5",
"x-oauth-scopes": "notifications, repo, workflow, write:org",
"x-ratelimit-limit": "5000",
"x-ratelimit-remaining": "4976",
"x-ratelimit-reset": "1656414682",
"x-ratelimit-resource": "core",
"x-ratelimit-used": "24",
"x-xss-protection": "0"
},
"data": {
"ref": "refs/heads/update-existing-pull-request",
"node_id": "MDM6UmVmMTYwOTg3NDkyOnJlZnMvaGVhZHMvdXBkYXRlLWV4aXN0aW5nLXB1bGwtcmVxdWVzdA==",
"url": "https://api.github.com/repos/gr2m/pull-request-test/git/refs/heads/update-existing-pull-request",
"object": {
"sha": "e4346a61815d43fa49531e0be9f6dd7d5c9a0ba7",
"type": "commit",
"url": "https://api.github.com/repos/gr2m/pull-request-test/git/commits/e4346a61815d43fa49531e0be9f6dd7d5c9a0ba7"
}
}
}
},
{
"request": {
"method": "PATCH",
Expand Down Expand Up @@ -736,8 +802,8 @@
"content-encoding": "gzip",
"content-security-policy": "default-src 'none'",
"content-type": "application/json; charset=utf-8",
"date": "Tue, 28 Jun 2022 00:56:41 GMT",
"etag": "W/\"8ebee5488b40f9ba432857ffe9dfd18c9d8fac17c98859650d3a5ae1aba45a6f\"",
"date": "Tue, 28 Jun 2022 10:54:31 GMT",
"etag": "W/\"adf2a9434bf0c7a98411f513a6c2be13d0b6fc8f3a008af9a6683d0055518db5\"",
"github-authentication-token-expiration": "2022-08-24 23:46:54 UTC",
"referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"server": "GitHub.com",
Expand All @@ -750,13 +816,13 @@
"x-github-api-version-selected": "",
"x-github-api-version-selected-reason": "unavailable",
"x-github-media-type": "github.v3; format=json",
"x-github-request-id": "DE68:8294:4109BE:4788FC:62BA51C9",
"x-github-request-id": "DA73:5D64:A58D3F:B4F281:62BADDE6",
"x-oauth-scopes": "notifications, repo, workflow, write:org",
"x-ratelimit-limit": "5000",
"x-ratelimit-remaining": "4829",
"x-ratelimit-reset": "1656378677",
"x-ratelimit-remaining": "4975",
"x-ratelimit-reset": "1656414682",
"x-ratelimit-resource": "core",
"x-ratelimit-used": "171",
"x-ratelimit-used": "25",
"x-xss-protection": "0"
},
"data": {
Expand Down Expand Up @@ -793,10 +859,10 @@
},
"body": "because",
"created_at": "2022-06-28T00:55:54Z",
"updated_at": "2022-06-28T00:55:54Z",
"updated_at": "2022-06-28T10:54:30Z",
"closed_at": null,
"merged_at": null,
"merge_commit_sha": "859480d7831b7100bc3243bb01c8d49019153eab",
"merge_commit_sha": "cd3fa21430cb34b66e143977ddd74932ee1f2f30",
"assignee": null,
"assignees": [],
"requested_reviewers": [],
Expand All @@ -808,11 +874,11 @@
"review_comments_url": "https://api.github.com/repos/gr2m/pull-request-test/pulls/100/comments",
"review_comment_url": "https://api.github.com/repos/gr2m/pull-request-test/pulls/comments{/number}",
"comments_url": "https://api.github.com/repos/gr2m/pull-request-test/issues/100/comments",
"statuses_url": "https://api.github.com/repos/gr2m/pull-request-test/statuses/1c2697d5b02dbe6f6c909e7628273ba2ac45ca63",
"statuses_url": "https://api.github.com/repos/gr2m/pull-request-test/statuses/e4346a61815d43fa49531e0be9f6dd7d5c9a0ba7",
"head": {
"label": "gr2m:update-existing-pull-request",
"ref": "update-existing-pull-request",
"sha": "1c2697d5b02dbe6f6c909e7628273ba2ac45ca63",
"sha": "e4346a61815d43fa49531e0be9f6dd7d5c9a0ba7",
"user": {
"login": "gr2m",
"id": 39992,
Expand Down Expand Up @@ -901,7 +967,7 @@
"deployments_url": "https://api.github.com/repos/gr2m/pull-request-test/deployments",
"created_at": "2018-12-08T23:26:26Z",
"updated_at": "2020-10-15T00:04:09Z",
"pushed_at": "2022-06-28T00:55:54Z",
"pushed_at": "2022-06-28T10:54:29Z",
"git_url": "git://github.com/gr2m/pull-request-test.git",
"ssh_url": "git@github.com:gr2m/pull-request-test.git",
"clone_url": "https://github.com/gr2m/pull-request-test.git",
Expand Down Expand Up @@ -1024,7 +1090,7 @@
"deployments_url": "https://api.github.com/repos/gr2m/pull-request-test/deployments",
"created_at": "2018-12-08T23:26:26Z",
"updated_at": "2020-10-15T00:04:09Z",
"pushed_at": "2022-06-28T00:55:54Z",
"pushed_at": "2022-06-28T10:54:29Z",
"git_url": "git://github.com/gr2m/pull-request-test.git",
"ssh_url": "git@github.com:gr2m/pull-request-test.git",
"clone_url": "https://github.com/gr2m/pull-request-test.git",
Expand Down Expand Up @@ -1078,7 +1144,7 @@
"href": "https://api.github.com/repos/gr2m/pull-request-test/pulls/100/commits"
},
"statuses": {
"href": "https://api.github.com/repos/gr2m/pull-request-test/statuses/1c2697d5b02dbe6f6c909e7628273ba2ac45ca63"
"href": "https://api.github.com/repos/gr2m/pull-request-test/statuses/e4346a61815d43fa49531e0be9f6dd7d5c9a0ba7"
}
},
"author_association": "OWNER",
Expand Down
Loading

0 comments on commit d57878f

Please sign in to comment.