@gitkraken/core-gitlens 0.45.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -1
- package/dist/git/models/remote.js +2 -2
- package/dist/git/models/remote.js.map +1 -1
- package/dist/git/remotes/matcher.js +25 -3
- package/dist/git/remotes/matcher.js.map +1 -1
- package/dist/git/utils/branchLanded.utils.d.ts +7 -0
- package/dist/git/utils/branchLanded.utils.js +10 -1
- package/dist/git/utils/branchLanded.utils.js.map +1 -1
- package/dist/git/utils/remote.utils.d.ts +1 -0
- package/dist/git/utils/remote.utils.js +14 -5
- package/dist/git/utils/remote.utils.js.map +1 -1
- package/dist/git-cli/parsers/logParser.js +227 -468
- package/dist/git-cli/parsers/logParser.js.map +1 -1
- package/dist/git-cli/parsers/refParser.js +4 -4
- package/dist/git-cli/parsers/refParser.js.map +1 -1
- package/dist/git-cli/providers/branches.d.ts +5 -0
- package/dist/git-cli/providers/branches.js +25 -21
- package/dist/git-cli/providers/branches.js.map +1 -1
- package/dist/git-cli/providers/config.js +2 -2
- package/dist/git-cli/providers/pausedOperations.js +2 -2
- package/dist/git-cli/providers/pausedOperations.js.map +1 -1
- package/dist/git-cli/providers/staging.js +1 -1
- package/dist/ipc/discovery.js +1 -1
- package/dist/plus/agents/providers/claudeCodeTranscript.js +6 -6
- package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -1
- package/dist/plus/ai/providers/openAICompatibleProviderBase.js +1 -1
- package/dist/plus/git-github/api/enterprisePullRequestMergePolicy.d.ts +31 -0
- package/dist/plus/git-github/api/enterprisePullRequestMergePolicy.js +166 -0
- package/dist/plus/git-github/api/enterprisePullRequestMergePolicy.js.map +1 -0
- package/dist/plus/git-github/api/github.d.ts +13 -5
- package/dist/plus/git-github/api/github.js +53 -13
- package/dist/plus/git-github/api/github.js.map +1 -1
- package/dist/plus/git-github/api/issueWrites.d.ts +7 -1
- package/dist/plus/git-github/api/issueWrites.js +62 -32
- package/dist/plus/git-github/api/issueWrites.js.map +1 -1
- package/dist/plus/git-github/api/pullRequestWrites.d.ts +7 -3
- package/dist/plus/git-github/api/pullRequestWrites.js +120 -67
- package/dist/plus/git-github/api/pullRequestWrites.js.map +1 -1
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.d.ts +44 -0
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js +199 -0
- package/dist/plus/integrations/authentication/cloudIntegrationAuthenticationProvider.js.map +1 -0
- package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +7 -0
- package/dist/plus/integrations/authentication/configuredIntegrationService.js +53 -7
- package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
- package/dist/plus/integrations/authentication/integrationAuthenticationProvider.d.ts +2 -38
- package/dist/plus/integrations/authentication/integrationAuthenticationProvider.js +0 -199
- package/dist/plus/integrations/authentication/integrationAuthenticationService.d.ts +4 -2
- package/dist/plus/integrations/authentication/integrationAuthenticationService.js +12 -1
- package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
- package/dist/plus/integrations/authentication/models.d.ts +0 -1
- package/dist/plus/integrations/authentication/models.js +1 -2
- package/dist/plus/integrations/authentication/models.js.map +1 -1
- package/dist/plus/integrations/constants.d.ts +0 -10
- package/dist/plus/integrations/constants.js +1 -95
- package/dist/plus/integrations/constants.js.map +1 -1
- package/dist/plus/integrations/context.d.ts +17 -17
- package/dist/plus/integrations/index.d.ts +44 -25
- package/dist/plus/integrations/index.js +41 -8
- package/dist/plus/integrations/index.js.map +1 -1
- package/dist/plus/integrations/integrationService.d.ts +24 -24
- package/dist/plus/integrations/integrationService.js +125 -34
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/lite.js +1 -1
- package/dist/plus/integrations/lite.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +81 -21
- package/dist/plus/integrations/models/actionablePullRequest.d.ts +213 -0
- package/dist/plus/integrations/models/actionablePullRequest.js +25 -0
- package/dist/plus/integrations/models/actionablePullRequest.js.map +1 -0
- package/dist/plus/integrations/models/gitHostIntegration.d.ts +13 -46
- package/dist/plus/integrations/models/gitHostIntegration.js +22 -8
- package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
- package/dist/plus/integrations/models/integration.d.ts +11 -175
- package/dist/plus/integrations/models/integration.js +22 -76
- package/dist/plus/integrations/models/integration.js.map +1 -1
- package/dist/plus/integrations/models/issueTrackerWrites.d.ts +128 -0
- package/dist/plus/integrations/models/issueTrackerWrites.js +0 -0
- package/dist/plus/integrations/models/issuesIntegration.d.ts +9 -5
- package/dist/plus/integrations/models/issuesIntegration.js +5 -3
- package/dist/plus/integrations/models/issuesIntegration.js.map +1 -1
- package/dist/plus/integrations/models/publicIntegration.d.ts +257 -0
- package/dist/plus/integrations/models/publicIntegration.js +21 -0
- package/dist/plus/integrations/models/publicIntegration.js.map +1 -0
- package/dist/plus/integrations/providerFilters.d.ts +58 -0
- package/dist/plus/integrations/providerFilters.js.map +1 -1
- package/dist/plus/integrations/providers/actionablePullRequests.d.ts +19 -0
- package/dist/plus/integrations/providers/actionablePullRequests.js +32 -0
- package/dist/plus/integrations/providers/actionablePullRequests.js.map +1 -0
- package/dist/plus/integrations/providers/apiClients.d.ts +1 -2
- package/dist/plus/integrations/providers/apiClients.js.map +1 -1
- package/dist/plus/integrations/providers/asana.d.ts +3 -2
- package/dist/plus/integrations/providers/asana.js +2 -1
- package/dist/plus/integrations/providers/asana.js.map +1 -1
- package/dist/plus/integrations/providers/azure/azure.d.ts +1 -1
- package/dist/plus/integrations/providers/azure/azure.js +1 -1
- package/dist/plus/integrations/providers/azure/azure.utils.d.ts +10 -3
- package/dist/plus/integrations/providers/azure/azure.utils.js +5 -1
- package/dist/plus/integrations/providers/azure/azure.utils.js.map +1 -1
- package/dist/plus/integrations/providers/azure/models.d.ts +1 -5
- package/dist/plus/integrations/providers/azure/models.js +1 -1
- package/dist/plus/integrations/providers/azure/models.js.map +1 -1
- package/dist/plus/integrations/providers/azureDevOps.d.ts +8 -5
- package/dist/plus/integrations/providers/azureDevOps.js +2 -1
- package/dist/plus/integrations/providers/azureDevOps.js.map +1 -1
- package/dist/plus/integrations/providers/azureDevOpsServer.d.ts +5 -4
- package/dist/plus/integrations/providers/azureDevOpsServer.js +3 -1
- package/dist/plus/integrations/providers/azureDevOpsServer.js.map +1 -1
- package/dist/plus/integrations/providers/bitbucket/bitbucket.d.ts +2 -2
- package/dist/plus/integrations/providers/bitbucket/bitbucket.js.map +1 -1
- package/dist/plus/integrations/providers/bitbucket/models.d.ts +1 -1
- package/dist/plus/integrations/providers/bitbucket/models.js.map +1 -1
- package/dist/plus/integrations/providers/bitbucket-server.d.ts +5 -4
- package/dist/plus/integrations/providers/bitbucket-server.js +2 -1
- package/dist/plus/integrations/providers/bitbucket-server.js.map +1 -1
- package/dist/plus/integrations/providers/bitbucket.d.ts +4 -3
- package/dist/plus/integrations/providers/bitbucket.js +2 -1
- package/dist/plus/integrations/providers/bitbucket.js.map +1 -1
- package/dist/plus/integrations/providers/github/github.d.ts +0 -1
- package/dist/plus/integrations/providers/github/github.js +1 -1
- package/dist/plus/integrations/providers/github/github.js.map +1 -1
- package/dist/plus/integrations/providers/github.d.ts +29 -11
- package/dist/plus/integrations/providers/github.js +195 -78
- package/dist/plus/integrations/providers/github.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/gitlab.d.ts +2 -2
- package/dist/plus/integrations/providers/gitlab/gitlab.js +1 -2
- package/dist/plus/integrations/providers/gitlab/gitlab.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/gitlab.utils.d.ts +14 -1
- package/dist/plus/integrations/providers/gitlab/gitlab.utils.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab/models.d.ts +2 -10
- package/dist/plus/integrations/providers/gitlab/models.js.map +1 -1
- package/dist/plus/integrations/providers/gitlab.d.ts +7 -5
- package/dist/plus/integrations/providers/gitlab.js +2 -1
- package/dist/plus/integrations/providers/gitlab.js.map +1 -1
- package/dist/plus/integrations/providers/issueSorts.d.ts +1 -0
- package/dist/plus/integrations/providers/jira-server.d.ts +4 -4
- package/dist/plus/integrations/providers/jira-server.js +3 -2
- package/dist/plus/integrations/providers/jira-server.js.map +1 -1
- package/dist/plus/integrations/providers/jira.d.ts +3 -3
- package/dist/plus/integrations/providers/jira.js +4 -3
- package/dist/plus/integrations/providers/jira.js.map +1 -1
- package/dist/plus/integrations/providers/jiraIssueByKey.d.ts +3 -1
- package/dist/plus/integrations/providers/jiraIssueByKey.js +1 -1
- package/dist/plus/integrations/providers/jiraIssueByKey.js.map +1 -1
- package/dist/plus/integrations/providers/jiraIssueWriteErrors.d.ts +10 -0
- package/dist/plus/integrations/providers/jiraIssueWriteErrors.js +68 -0
- package/dist/plus/integrations/providers/jiraIssueWriteErrors.js.map +1 -0
- package/dist/plus/integrations/providers/jiraIssueWrites.d.ts +40 -0
- package/dist/plus/integrations/providers/jiraIssueWrites.js +397 -0
- package/dist/plus/integrations/providers/jiraIssueWrites.js.map +1 -0
- package/dist/plus/integrations/providers/linear.d.ts +4 -3
- package/dist/plus/integrations/providers/linear.js +3 -2
- package/dist/plus/integrations/providers/linear.js.map +1 -1
- package/dist/plus/integrations/providers/linearIssuesEtag.d.ts +1 -1
- package/dist/plus/integrations/providers/linearIssuesEtag.js +1 -1
- package/dist/plus/integrations/providers/linearIssuesEtag.js.map +1 -1
- package/dist/plus/integrations/providers/metadata.d.ts +136 -0
- package/dist/plus/integrations/providers/metadata.js +513 -0
- package/dist/plus/integrations/providers/metadata.js.map +1 -0
- package/dist/plus/integrations/providers/models.d.ts +10 -206
- package/dist/plus/integrations/providers/models.js +8 -539
- package/dist/plus/integrations/providers/models.js.map +1 -1
- package/dist/plus/integrations/providers/providersApi.d.ts +7 -3
- package/dist/plus/integrations/providers/providersApi.js +23 -11
- package/dist/plus/integrations/providers/providersApi.js.map +1 -1
- package/dist/plus/integrations/providers/trello.d.ts +1 -1
- package/dist/plus/integrations/providers/trello.js +2 -1
- package/dist/plus/integrations/providers/trello.js.map +1 -1
- package/dist/plus/integrations/providers/utils/providerPaging.d.ts +2 -0
- package/dist/plus/integrations/providers/utils/providerPaging.js +3 -2
- package/dist/plus/integrations/providers/utils/providerPaging.js.map +1 -1
- package/dist/plus/integrations/providers/utils.d.ts +119 -10
- package/dist/plus/integrations/providers/utils.js +57 -3
- package/dist/plus/integrations/providers/utils.js.map +1 -1
- package/dist/plus/integrations/reads/autolinks.d.ts +1 -1
- package/dist/plus/integrations/reads/autolinks.js +1 -1
- package/dist/plus/integrations/reads/autolinks.js.map +1 -1
- package/dist/plus/integrations/reads/broaden.d.ts +1 -1
- package/dist/plus/integrations/reads/broaden.js +3 -2
- package/dist/plus/integrations/reads/broaden.js.map +1 -1
- package/dist/plus/integrations/reads/context.d.ts +1 -1
- package/dist/plus/integrations/reads/counts.d.ts +1 -88
- package/dist/plus/integrations/reads/counts.js +4 -2
- package/dist/plus/integrations/reads/counts.js.map +1 -1
- package/dist/plus/integrations/reads/currentAccount.d.ts +1 -18
- package/dist/plus/integrations/reads/currentAccount.js.map +1 -1
- package/dist/plus/integrations/reads/drains.d.ts +4 -3
- package/dist/plus/integrations/reads/drains.js +1 -1
- package/dist/plus/integrations/reads/drains.js.map +1 -1
- package/dist/plus/integrations/reads/etag.d.ts +174 -3
- package/dist/plus/integrations/reads/etag.js +69 -14
- package/dist/plus/integrations/reads/etag.js.map +1 -1
- package/dist/plus/integrations/reads/filters.d.ts +3 -61
- package/dist/plus/integrations/reads/filters.js +1 -1
- package/dist/plus/integrations/reads/filters.js.map +1 -1
- package/dist/plus/integrations/reads/hierarchy.d.ts +1 -1
- package/dist/plus/integrations/reads/hierarchy.js +4 -2
- package/dist/plus/integrations/reads/hierarchy.js.map +1 -1
- package/dist/plus/integrations/reads/issueBatch.d.ts +2 -102
- package/dist/plus/integrations/reads/issueBatch.js +3 -4
- package/dist/plus/integrations/reads/issueBatch.js.map +1 -1
- package/dist/plus/integrations/reads/issueTracker.d.ts +1 -1
- package/dist/plus/integrations/reads/issueTracker.js +4 -3
- package/dist/plus/integrations/reads/issueTracker.js.map +1 -1
- package/dist/plus/integrations/reads/issues.d.ts +1 -1
- package/dist/plus/integrations/reads/issues.js +4 -2
- package/dist/plus/integrations/reads/issues.js.map +1 -1
- package/dist/plus/integrations/reads/paging.d.ts +1 -1
- package/dist/plus/integrations/reads/paging.js +1 -1
- package/dist/plus/integrations/reads/paging.js.map +1 -1
- package/dist/plus/integrations/reads/pullRequestActivity.d.ts +1 -24
- package/dist/plus/integrations/reads/pullRequestActivity.js +2 -1
- package/dist/plus/integrations/reads/pullRequestActivity.js.map +1 -1
- package/dist/plus/integrations/reads/pullRequestBatch.d.ts +2 -56
- package/dist/plus/integrations/reads/pullRequestBatch.js +23 -3
- package/dist/plus/integrations/reads/pullRequestBatch.js.map +1 -1
- package/dist/plus/integrations/reads/pullRequestBranches.d.ts +1 -47
- package/dist/plus/integrations/reads/pullRequestBranches.js +2 -1
- package/dist/plus/integrations/reads/pullRequestBranches.js.map +1 -1
- package/dist/plus/integrations/reads/pullRequestCheckLogs.d.ts +1 -15
- package/dist/plus/integrations/reads/pullRequestCheckLogs.js +2 -1
- package/dist/plus/integrations/reads/pullRequestCheckLogs.js.map +1 -1
- package/dist/plus/integrations/reads/pullRequests.js +4 -2
- package/dist/plus/integrations/reads/pullRequests.js.map +1 -1
- package/dist/plus/integrations/reads/pullRequestsForCommits.d.ts +1 -16
- package/dist/plus/integrations/reads/pullRequestsForCommits.js +2 -1
- package/dist/plus/integrations/reads/pullRequestsForCommits.js.map +1 -1
- package/dist/plus/integrations/reads/resolveRepository.js +10 -5
- package/dist/plus/integrations/reads/resolveRepository.js.map +1 -1
- package/dist/plus/integrations/reads/searchIssues.js +2 -1
- package/dist/plus/integrations/reads/searchIssues.js.map +1 -1
- package/dist/plus/integrations/reads/searchPullRequests.js +2 -1
- package/dist/plus/integrations/reads/searchPullRequests.js.map +1 -1
- package/dist/plus/integrations/reads/sweeps.d.ts +1 -1
- package/dist/plus/integrations/reads/sweeps.js +3 -2
- package/dist/plus/integrations/reads/sweeps.js.map +1 -1
- package/dist/plus/integrations/reads/warnings.d.ts +1 -1
- package/dist/plus/integrations/reads/warnings.js +1 -1
- package/dist/plus/integrations/reads/warnings.js.map +1 -1
- package/dist/plus/integrations/results.d.ts +324 -2
- package/dist/plus/integrations/results.js.map +1 -1
- package/dist/plus/integrations/telemetry.d.ts +0 -10
- package/dist/plus/integrations/telemetry.js +0 -11
- package/dist/plus/integrations/utils/domain.utils.d.ts +1 -0
- package/dist/plus/integrations/utils/domain.utils.js +10 -2
- package/dist/plus/integrations/utils/domain.utils.js.map +1 -1
- package/dist/plus/integrations/utils/integration.utils.d.ts +2 -6
- package/dist/plus/integrations/utils/integration.utils.js +8 -9
- package/dist/plus/integrations/utils/integration.utils.js.map +1 -1
- package/dist/utils/env/node/exec.js +2 -2
- package/dist/utils/keys/chord.d.ts +13 -2
- package/dist/utils/keys/chord.js +76 -17
- package/dist/utils/keys/chord.js.map +1 -1
- package/dist/utils/keys/keybinding.d.ts +12 -0
- package/dist/utils/keys/keybinding.js +52 -2
- package/dist/utils/keys/keybinding.js.map +1 -1
- package/dist/utils/markdown.d.ts +21 -0
- package/dist/utils/markdown.js +33 -1
- package/dist/utils/markdown.js.map +1 -1
- package/docs/integrations.md +174 -19
- package/package.json +5 -1
- package/dist/plus/integrations/authentication/integrationAuthenticationProvider.js.map +0 -1
- package/dist/plus/integrations/telemetry.js.map +0 -1
|
@@ -40,6 +40,8 @@ export type IssueWriteResult = {
|
|
|
40
40
|
} | {
|
|
41
41
|
ok: false;
|
|
42
42
|
reason: 'unsupported' | 'no-connection' | 'forbidden' | 'not-found' | 'invalid-input' | 'rate-limit' | 'unknown';
|
|
43
|
+
/** An unconfirmed result that failed before the mutation could be sent. */
|
|
44
|
+
mutationDispatched?: false;
|
|
43
45
|
};
|
|
44
46
|
export type GitHubIssueMutation = GitHubIssueWrite | (GitHubIssueDelete & {
|
|
45
47
|
action: 'delete';
|
|
@@ -52,6 +54,10 @@ export declare function isValidGitHubIssueMutation(input: GitHubIssueMutation):
|
|
|
52
54
|
export declare function issueWriteFailure(ex: unknown): Extract<IssueWriteResult, {
|
|
53
55
|
ok: false;
|
|
54
56
|
}>;
|
|
55
|
-
export declare function mutateGitHubIssue(input: GitHubIssueMutation, graphql: GraphqlRequest
|
|
57
|
+
export declare function mutateGitHubIssue(input: GitHubIssueMutation, graphql: GraphqlRequest, { origin, isSessionCurrent }: {
|
|
58
|
+
origin?: string;
|
|
59
|
+
isSessionCurrent?: () => Promise<boolean>;
|
|
60
|
+
}): Promise<IssueWriteResult>;
|
|
61
|
+
export declare function isGitHubWriteUrlOnInstallation(value: unknown, origin: string | undefined): boolean;
|
|
56
62
|
//#endregion
|
|
57
63
|
//# sourceMappingURL=issueWrites.d.ts.map
|
|
@@ -77,9 +77,15 @@ function issueWriteFailure(ex) {
|
|
|
77
77
|
reason: "unknown"
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
-
async function mutateGitHubIssue(input, graphql) {
|
|
80
|
+
async function mutateGitHubIssue(input, graphql, { origin, isSessionCurrent }) {
|
|
81
|
+
let dispatched = false;
|
|
82
|
+
const mutate = (query, variables) => {
|
|
83
|
+
dispatched = true;
|
|
84
|
+
return graphql(query, variables);
|
|
85
|
+
};
|
|
81
86
|
try {
|
|
82
87
|
const { owner, repo } = input;
|
|
88
|
+
const checkDelete = input.action === "delete" || input.action === "resolve" && input.intent === "delete";
|
|
83
89
|
const target = input.action === "create" ? await graphql(`
|
|
84
90
|
query IssueCreateTarget($owner: String!, $repo: String!) {
|
|
85
91
|
repository(owner: $owner, name: $repo, followRenames: false) {
|
|
@@ -91,7 +97,7 @@ async function mutateGitHubIssue(input, graphql) {
|
|
|
91
97
|
`, {
|
|
92
98
|
owner,
|
|
93
99
|
repo
|
|
94
|
-
}) : await graphql(`query IssueWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID
|
|
100
|
+
}) : await graphql(`query IssueWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID!) {
|
|
95
101
|
repository(owner: $owner, name: $repo, followRenames: false) {
|
|
96
102
|
id hasIssuesEnabled isArchived
|
|
97
103
|
}
|
|
@@ -99,14 +105,13 @@ async function mutateGitHubIssue(input, graphql) {
|
|
|
99
105
|
__typename
|
|
100
106
|
... on Issue {
|
|
101
107
|
${issueFields}
|
|
102
|
-
viewerCanDelete
|
|
108
|
+
${checkDelete ? "viewerCanDelete" : ""}
|
|
103
109
|
}
|
|
104
110
|
}
|
|
105
111
|
}`, {
|
|
106
112
|
owner,
|
|
107
113
|
repo,
|
|
108
|
-
expectedNodeId: input.expectedNodeId
|
|
109
|
-
checkDelete: input.action === "delete" || input.action === "resolve" && input.intent === "delete"
|
|
114
|
+
expectedNodeId: input.expectedNodeId
|
|
110
115
|
});
|
|
111
116
|
const repository = target?.repository;
|
|
112
117
|
if (repository == null) return {
|
|
@@ -121,38 +126,43 @@ async function mutateGitHubIssue(input, graphql) {
|
|
|
121
126
|
ok: false,
|
|
122
127
|
reason: "unsupported"
|
|
123
128
|
};
|
|
124
|
-
if (input.action === "create")
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
if (input.action === "create") {
|
|
130
|
+
if (isSessionCurrent != null && !await isSessionCurrent()) return {
|
|
131
|
+
ok: false,
|
|
132
|
+
reason: "no-connection"
|
|
133
|
+
};
|
|
134
|
+
return await writeIssue(mutate, "createIssue", "CreateIssueInput", {
|
|
135
|
+
repositoryId: repository.id,
|
|
136
|
+
title: input.title,
|
|
137
|
+
body: input.body
|
|
138
|
+
}, origin);
|
|
139
|
+
}
|
|
129
140
|
const issue = target?.node;
|
|
130
|
-
if (issue?.__typename !== "Issue" || issue.number !== input.number || issue.repository.id !== repository.id || issue.repository.owner.login.toLowerCase() !== owner.toLowerCase() || issue.repository.name.toLowerCase() !== repo.toLowerCase()) return {
|
|
141
|
+
if (issue?.__typename !== "Issue" || !isGitHubWriteUrlOnInstallation(issue.url, origin) || issue.number !== input.number || issue.repository.id !== repository.id || issue.repository.owner.login.toLowerCase() !== owner.toLowerCase() || issue.repository.name.toLowerCase() !== repo.toLowerCase()) return {
|
|
131
142
|
ok: false,
|
|
132
143
|
reason: "not-found"
|
|
133
144
|
};
|
|
145
|
+
if (checkDelete && issue.viewerCanDelete !== true) return {
|
|
146
|
+
ok: false,
|
|
147
|
+
reason: "forbidden"
|
|
148
|
+
};
|
|
149
|
+
if (input.action === "resolve") return toIssueWriteResult(issue);
|
|
150
|
+
if (isSessionCurrent != null && !await isSessionCurrent()) return {
|
|
151
|
+
ok: false,
|
|
152
|
+
reason: "no-connection"
|
|
153
|
+
};
|
|
134
154
|
switch (input.action) {
|
|
135
|
-
case "
|
|
136
|
-
if (input.intent === "delete" && issue.viewerCanDelete !== true) return {
|
|
137
|
-
ok: false,
|
|
138
|
-
reason: "forbidden"
|
|
139
|
-
};
|
|
140
|
-
return toIssueWriteResult(issue);
|
|
141
|
-
case "edit": return await writeIssue(graphql, "updateIssue", "UpdateIssueInput", {
|
|
155
|
+
case "edit": return await writeIssue(mutate, "updateIssue", "UpdateIssueInput", {
|
|
142
156
|
id: issue.id,
|
|
143
157
|
title: input.title,
|
|
144
158
|
body: input.body
|
|
145
|
-
});
|
|
146
|
-
case "set-state": return input.state === "open" ? await writeIssue(
|
|
159
|
+
}, origin);
|
|
160
|
+
case "set-state": return input.state === "open" ? await writeIssue(mutate, "reopenIssue", "ReopenIssueInput", { issueId: issue.id }, origin) : await writeIssue(mutate, "closeIssue", "CloseIssueInput", {
|
|
147
161
|
issueId: issue.id,
|
|
148
162
|
stateReason: input.reason === "completed" ? "COMPLETED" : "NOT_PLANNED"
|
|
149
|
-
});
|
|
163
|
+
}, origin);
|
|
150
164
|
case "delete": {
|
|
151
|
-
|
|
152
|
-
ok: false,
|
|
153
|
-
reason: "forbidden"
|
|
154
|
-
};
|
|
155
|
-
const deletedRepositoryId = (await graphql(`
|
|
165
|
+
const deletedRepositoryId = (await mutate(`
|
|
156
166
|
mutation DeleteIssue($issueId: ID!) {
|
|
157
167
|
deleteIssue(input: { issueId: $issueId }) {
|
|
158
168
|
repository {
|
|
@@ -168,18 +178,38 @@ async function mutateGitHubIssue(input, graphql) {
|
|
|
168
178
|
}
|
|
169
179
|
}
|
|
170
180
|
} catch (ex) {
|
|
171
|
-
|
|
181
|
+
if (origin != null && ex instanceof GraphqlResponseError && ex.data == null && ex.errors?.some((error) => {
|
|
182
|
+
const code = error.extensions?.code;
|
|
183
|
+
return code === "undefinedField" || code === "argumentNotAccepted" || code === "variableRequiresValidType";
|
|
184
|
+
})) return {
|
|
185
|
+
ok: false,
|
|
186
|
+
reason: "unsupported"
|
|
187
|
+
};
|
|
188
|
+
if (dispatched && ex instanceof GraphqlResponseError && ex.errors?.some((error) => error.path != null && error.path.length > 1)) return {
|
|
189
|
+
ok: false,
|
|
190
|
+
reason: "unknown"
|
|
191
|
+
};
|
|
192
|
+
const failure = issueWriteFailure(ex);
|
|
193
|
+
return origin != null && failure.reason === "unknown" && !dispatched ? {
|
|
194
|
+
...failure,
|
|
195
|
+
mutationDispatched: false
|
|
196
|
+
} : failure;
|
|
172
197
|
}
|
|
173
198
|
}
|
|
174
|
-
async function writeIssue(graphql, mutation, inputType, input) {
|
|
175
|
-
const
|
|
199
|
+
async function writeIssue(graphql, mutation, inputType, input, origin) {
|
|
200
|
+
const issue = (await graphql(`mutation WriteIssue($input: ${inputType}!) {
|
|
176
201
|
change: ${mutation}(input: $input) { issue { ${issueFields} } }
|
|
177
|
-
}`, { input });
|
|
178
|
-
return
|
|
202
|
+
}`, { input }))?.change?.issue;
|
|
203
|
+
return issue != null && isGitHubWriteUrlOnInstallation(issue.url, origin) ? toIssueWriteResult(issue) : {
|
|
179
204
|
ok: false,
|
|
180
205
|
reason: "unknown"
|
|
181
206
|
};
|
|
182
207
|
}
|
|
208
|
+
function isGitHubWriteUrlOnInstallation(value, origin) {
|
|
209
|
+
if (origin == null) return true;
|
|
210
|
+
const url = typeof value === "string" ? URL.parse(value) : null;
|
|
211
|
+
return url?.origin === origin && (url.protocol === "https:" || url.protocol === "http:") && !url.username && !url.password;
|
|
212
|
+
}
|
|
183
213
|
function toIssueWriteResult(issue, deletedFromDifferentRepository = false) {
|
|
184
214
|
return {
|
|
185
215
|
ok: true,
|
|
@@ -197,6 +227,6 @@ function toIssueWriteResult(issue, deletedFromDifferentRepository = false) {
|
|
|
197
227
|
};
|
|
198
228
|
}
|
|
199
229
|
//#endregion
|
|
200
|
-
export { isValidGitHubIssueMutation, issueWriteFailure, mutateGitHubIssue };
|
|
230
|
+
export { isGitHubWriteUrlOnInstallation, isValidGitHubIssueMutation, issueWriteFailure, mutateGitHubIssue };
|
|
201
231
|
|
|
202
232
|
//# sourceMappingURL=issueWrites.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"issueWrites.js","names":[],"sources":["../../../../../plus/git-github/src/api/issueWrites.ts"],"sourcesContent":["import { GraphqlResponseError } from '@octokit/graphql';\nimport { RequestError } from '@octokit/request-error';\nimport type { RequestParameters } from '@octokit/types';\nimport { RequestRateLimitError } from '@gitlens/git/errors.js';\n\ntype GitHubIssueWriteTarget = { owner: string; repo: string };\n\nexport type GitHubIssueDelete = GitHubIssueWriteTarget & { number: number; expectedNodeId: string };\n\nexport type GitHubIssueWrite =\n\t| (GitHubIssueWriteTarget & { action: 'create'; title: string; body?: string })\n\t| (GitHubIssueDelete &\n\t\t\t(\n\t\t\t\t| { action: 'edit'; title?: string; body?: string }\n\t\t\t\t| { action: 'set-state'; state: 'open' }\n\t\t\t\t| { action: 'set-state'; state: 'closed'; reason: 'completed' | 'not_planned' }\n\t\t\t));\n\nexport type IssueWriteResult =\n\t| {\n\t\t\tok: true;\n\t\t\tissue: {\n\t\t\t\towner: string;\n\t\t\t\trepo: string;\n\t\t\t\tnumber: number;\n\t\t\t\tnodeId: string;\n\t\t\t\turl: string;\n\t\t\t\ttitle: string;\n\t\t\t\tbody: string;\n\t\t\t\tstate: 'open' | 'closed';\n\t\t\t};\n\t\t\tdeletedFromDifferentRepository?: true;\n\t }\n\t| {\n\t\t\tok: false;\n\t\t\treason:\n\t\t\t\t| 'unsupported'\n\t\t\t\t| 'no-connection'\n\t\t\t\t| 'forbidden'\n\t\t\t\t| 'not-found'\n\t\t\t\t| 'invalid-input'\n\t\t\t\t| 'rate-limit'\n\t\t\t\t| 'unknown';\n\t };\n\nexport type GitHubIssueMutation =\n\t| GitHubIssueWrite\n\t| (GitHubIssueDelete & { action: 'delete' })\n\t| (GitHubIssueDelete & { action: 'resolve'; intent?: 'delete' });\ntype GraphqlRequest = <T>(query: string, variables: RequestParameters) => Promise<T | undefined>;\n\nconst issueFields = `\n\tid number url title body state\n\trepository { id owner { login } name }\n`;\n\ntype IssueNode = {\n\tid: string;\n\tnumber: number;\n\turl: string;\n\ttitle: string;\n\tbody: string;\n\tstate: 'OPEN' | 'CLOSED';\n\trepository: { id: string; owner: { login: string }; name: string };\n};\n\ntype RepositoryNode = {\n\tid: string;\n\thasIssuesEnabled: boolean;\n\tisArchived: boolean;\n};\n\ntype WriteTarget = {\n\trepository: RepositoryNode | null;\n\tnode?: (IssueNode & { __typename: string; viewerCanDelete?: boolean }) | null;\n};\n\nexport function isValidGitHubIssueMutation(input: GitHubIssueMutation): boolean {\n\tif (\n\t\ttypeof input.owner !== 'string' ||\n\t\t!/^[a-z\\d_-]+$/i.test(input.owner) ||\n\t\ttypeof input.repo !== 'string' ||\n\t\t!/^[a-z\\d._-]+$/i.test(input.repo) ||\n\t\tinput.repo === '.' ||\n\t\tinput.repo === '..'\n\t) {\n\t\treturn false;\n\t}\n\n\tif (\n\t\tinput.action !== 'create' &&\n\t\t(!Number.isInteger(input.number) ||\n\t\t\tinput.number < 1 ||\n\t\t\tinput.number > 2147483647 ||\n\t\t\ttypeof input.expectedNodeId !== 'string' ||\n\t\t\t!input.expectedNodeId.trim())\n\t) {\n\t\treturn false;\n\t}\n\n\tswitch (input.action) {\n\t\tcase 'create':\n\t\t\treturn isIssueTitle(input.title) && (input.body === undefined || typeof input.body === 'string');\n\t\tcase 'edit':\n\t\t\treturn (\n\t\t\t\t(input.title !== undefined || input.body !== undefined) &&\n\t\t\t\t(input.title === undefined || isIssueTitle(input.title)) &&\n\t\t\t\t(input.body === undefined || typeof input.body === 'string')\n\t\t\t);\n\t\tcase 'set-state':\n\t\t\treturn (\n\t\t\t\tinput.state === 'open' ||\n\t\t\t\t(input.state === 'closed' && (input.reason === 'completed' || input.reason === 'not_planned'))\n\t\t\t);\n\t\tcase 'delete':\n\t\t\treturn true;\n\t\tcase 'resolve':\n\t\t\treturn input.intent === undefined || input.intent === 'delete';\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction isIssueTitle(title: unknown): title is string {\n\treturn typeof title === 'string' && title.trim().length > 0;\n}\n\nexport function issueWriteFailure(ex: unknown): Extract<IssueWriteResult, { ok: false }> {\n\tif (RequestRateLimitError.is(ex)) return { ok: false, reason: 'rate-limit' };\n\n\tif (ex instanceof GraphqlResponseError) {\n\t\tif (ex.errors?.some(error => error.type === 'RATE_LIMIT' || error.type === 'RATE_LIMITED')) {\n\t\t\treturn { ok: false, reason: 'rate-limit' };\n\t\t}\n\n\t\tswitch (ex.errors?.[0]?.type) {\n\t\t\tcase 'NOT_FOUND':\n\t\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t\tcase 'FORBIDDEN':\n\t\t\tcase 'INSUFFICIENT_SCOPES':\n\t\t\t\treturn { ok: false, reason: 'forbidden' };\n\t\t\tcase 'BAD_USER_INPUT':\n\t\t\tcase 'UNPROCESSABLE':\n\t\t\t\treturn { ok: false, reason: 'invalid-input' };\n\t\t}\n\t}\n\n\tif (ex instanceof RequestError) {\n\t\tswitch (ex.status) {\n\t\t\tcase 400:\n\t\t\tcase 422:\n\t\t\t\treturn { ok: false, reason: 'invalid-input' };\n\t\t\tcase 401:\n\t\t\t\treturn { ok: false, reason: 'no-connection' };\n\t\t\tcase 403:\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\treason: ex.message.toLowerCase().includes('rate limit') ? 'rate-limit' : 'forbidden',\n\t\t\t\t};\n\t\t\tcase 404:\n\t\t\tcase 410:\n\t\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t\tcase 429:\n\t\t\t\treturn { ok: false, reason: 'rate-limit' };\n\t\t}\n\t}\n\n\treturn { ok: false, reason: 'unknown' };\n}\n\nexport async function mutateGitHubIssue(\n\tinput: GitHubIssueMutation,\n\tgraphql: GraphqlRequest,\n): Promise<IssueWriteResult> {\n\ttry {\n\t\tconst { owner, repo } = input;\n\t\tconst target =\n\t\t\tinput.action === 'create'\n\t\t\t\t? await graphql<WriteTarget>(\n\t\t\t\t\t\t`\n\t\t\t\t\t\t\tquery IssueCreateTarget($owner: String!, $repo: String!) {\n\t\t\t\t\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\t\t\thasIssuesEnabled\n\t\t\t\t\t\t\t\t\tisArchived\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t`,\n\t\t\t\t\t\t{ owner: owner, repo: repo },\n\t\t\t\t\t)\n\t\t\t\t: await graphql<WriteTarget>(\n\t\t\t\t\t\t`query IssueWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID!, $checkDelete: Boolean!) {\n\t\t\t\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t\t\t\tid hasIssuesEnabled isArchived\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tnode(id: $expectedNodeId) {\n\t\t\t\t\t\t\t\t__typename\n\t\t\t\t\t\t\t\t... on Issue {\n\t\t\t\t\t\t\t\t\t${issueFields}\n\t\t\t\t\t\t\t\t\tviewerCanDelete @include(if: $checkDelete)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\towner: owner,\n\t\t\t\t\t\t\trepo: repo,\n\t\t\t\t\t\t\texpectedNodeId: input.expectedNodeId,\n\t\t\t\t\t\t\tcheckDelete:\n\t\t\t\t\t\t\t\tinput.action === 'delete' || (input.action === 'resolve' && input.intent === 'delete'),\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\tconst repository = target?.repository;\n\t\tif (repository == null) return { ok: false, reason: 'not-found' };\n\t\tif (repository.isArchived) return { ok: false, reason: 'forbidden' };\n\t\tif (!repository.hasIssuesEnabled) return { ok: false, reason: 'unsupported' };\n\n\t\tif (input.action === 'create') {\n\t\t\treturn await writeIssue(graphql, 'createIssue', 'CreateIssueInput', {\n\t\t\t\trepositoryId: repository.id,\n\t\t\t\ttitle: input.title,\n\t\t\t\tbody: input.body,\n\t\t\t});\n\t\t}\n\n\t\tconst issue = target?.node;\n\t\tif (\n\t\t\tissue?.__typename !== 'Issue' ||\n\t\t\tissue.number !== input.number ||\n\t\t\tissue.repository.id !== repository.id ||\n\t\t\tissue.repository.owner.login.toLowerCase() !== owner.toLowerCase() ||\n\t\t\tissue.repository.name.toLowerCase() !== repo.toLowerCase()\n\t\t) {\n\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t}\n\n\t\tswitch (input.action) {\n\t\t\tcase 'resolve':\n\t\t\t\tif (input.intent === 'delete' && issue.viewerCanDelete !== true) {\n\t\t\t\t\treturn { ok: false, reason: 'forbidden' };\n\t\t\t\t}\n\t\t\t\treturn toIssueWriteResult(issue);\n\t\t\tcase 'edit':\n\t\t\t\treturn await writeIssue(graphql, 'updateIssue', 'UpdateIssueInput', {\n\t\t\t\t\tid: issue.id,\n\t\t\t\t\ttitle: input.title,\n\t\t\t\t\tbody: input.body,\n\t\t\t\t});\n\t\t\tcase 'set-state':\n\t\t\t\treturn input.state === 'open'\n\t\t\t\t\t? await writeIssue(graphql, 'reopenIssue', 'ReopenIssueInput', { issueId: issue.id })\n\t\t\t\t\t: await writeIssue(graphql, 'closeIssue', 'CloseIssueInput', {\n\t\t\t\t\t\t\tissueId: issue.id,\n\t\t\t\t\t\t\tstateReason: input.reason === 'completed' ? 'COMPLETED' : 'NOT_PLANNED',\n\t\t\t\t\t\t});\n\t\t\tcase 'delete': {\n\t\t\t\tif (issue.viewerCanDelete !== true) return { ok: false, reason: 'forbidden' };\n\n\t\t\t\tconst result = await graphql<{ deleteIssue: { repository: { id: string } | null } | null }>(\n\t\t\t\t\t`\n\t\t\t\t\t\tmutation DeleteIssue($issueId: ID!) {\n\t\t\t\t\t\t\tdeleteIssue(input: { issueId: $issueId }) {\n\t\t\t\t\t\t\t\trepository {\n\t\t\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t`,\n\t\t\t\t\t{ issueId: issue.id },\n\t\t\t\t);\n\t\t\t\tconst deletedRepositoryId = result?.deleteIssue?.repository?.id;\n\t\t\t\treturn typeof deletedRepositoryId === 'string' && deletedRepositoryId.length > 0\n\t\t\t\t\t? toIssueWriteResult(issue, deletedRepositoryId !== repository.id)\n\t\t\t\t\t: { ok: false, reason: 'unknown' };\n\t\t\t}\n\t\t}\n\t} catch (ex) {\n\t\treturn issueWriteFailure(ex);\n\t}\n}\n\nasync function writeIssue(\n\tgraphql: GraphqlRequest,\n\tmutation: 'createIssue' | 'updateIssue' | 'closeIssue' | 'reopenIssue',\n\tinputType: string,\n\tinput: Record<string, string | undefined>,\n): Promise<IssueWriteResult> {\n\tconst result = await graphql<{ change: { issue: IssueNode | null } | null }>(\n\t\t`mutation WriteIssue($input: ${inputType}!) {\n\t\t\tchange: ${mutation}(input: $input) { issue { ${issueFields} } }\n\t\t}`,\n\t\t{ input: input },\n\t);\n\treturn result?.change?.issue != null ? toIssueWriteResult(result.change.issue) : { ok: false, reason: 'unknown' };\n}\n\nfunction toIssueWriteResult(issue: IssueNode, deletedFromDifferentRepository = false): IssueWriteResult {\n\treturn {\n\t\tok: true,\n\t\t...(deletedFromDifferentRepository && { deletedFromDifferentRepository: true }),\n\t\tissue: {\n\t\t\towner: issue.repository.owner.login,\n\t\t\trepo: issue.repository.name,\n\t\t\tnumber: issue.number,\n\t\t\tnodeId: issue.id,\n\t\t\turl: issue.url,\n\t\t\ttitle: issue.title,\n\t\t\tbody: issue.body,\n\t\t\tstate: issue.state === 'CLOSED' ? 'closed' : 'open',\n\t\t},\n\t};\n}\n"],"mappings":";;;;AAmDA,MAAM,cAAc;;;;AA0BpB,SAAgB,2BAA2B,OAAqC;CAC/E,IACC,OAAO,MAAM,UAAU,YACvB,CAAC,gBAAgB,KAAK,MAAM,KAAK,KACjC,OAAO,MAAM,SAAS,YACtB,CAAC,iBAAiB,KAAK,MAAM,IAAI,KACjC,MAAM,SAAS,OACf,MAAM,SAAS,MAEf,OAAO;CAGR,IACC,MAAM,WAAW,aAChB,CAAC,OAAO,UAAU,MAAM,MAAM,KAC9B,MAAM,SAAS,KACf,MAAM,SAAS,cACf,OAAO,MAAM,mBAAmB,YAChC,CAAC,MAAM,eAAe,KAAK,IAE5B,OAAO;CAGR,QAAQ,MAAM,QAAd;EACC,KAAK,UACJ,OAAO,aAAa,MAAM,KAAK,MAAM,MAAM,SAAS,KAAA,KAAa,OAAO,MAAM,SAAS;EACxF,KAAK,QACJ,QACE,MAAM,UAAU,KAAA,KAAa,MAAM,SAAS,KAAA,OAC5C,MAAM,UAAU,KAAA,KAAa,aAAa,MAAM,KAAK,OACrD,MAAM,SAAS,KAAA,KAAa,OAAO,MAAM,SAAS;EAErD,KAAK,aACJ,OACC,MAAM,UAAU,UACf,MAAM,UAAU,aAAa,MAAM,WAAW,eAAe,MAAM,WAAW;EAEjF,KAAK,UACJ,OAAO;EACR,KAAK,WACJ,OAAO,MAAM,WAAW,KAAA,KAAa,MAAM,WAAW;EACvD,SACC,OAAO;CACT;AACD;AAEA,SAAS,aAAa,OAAiC;CACtD,OAAO,OAAO,UAAU,YAA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IAAY;IAc5E,MAAM,uBAAsB,MAZP,QACpB;;;;;;;;QASA,EAAE,SAAS,MAAM,GAAG,CACrB,EAAA,EACoC,aAAa,YAAY;IAC7D,OAAO,OAAO,wBAAwB,YAAY,oBAAoB,SAAS,IAC5E,mBAAmB,OAAO,wBAAwB,WAAW,EAAE,IAC/D;KAAE,IAAI;KAAO,QAAQ;IAAU;GACnC;EACD;CACD,SAAS,IAAI;EACZ,OAAO,kBAAkB,EAAE;CAC5B;AACD;AAEA,eAAe,WACd,SACA,UACA,WACA,OAC4B;CAC5B,MAAM,SAAS,MAAM,QACpB,+BAA+B,UAAU;aAC9B,SAAS,4BAA4B,YAAY;MAE5D,EAAS,MAAM,CAChB;CACA,OAAO,QAAQ,QAAQ,SAAS,OAAO,mBAAmB,OAAO,OAAO,KAAK,IAAI;EAAE,IAAI;EAAO,QAAQ;CAAU;AACjH;AAEA,SAAS,mBAAmB,OAAkB,iCAAiC,OAAyB;CACvG,OAAO;EACN,IAAI;EACJ,GAAI,kCAAkC,EAAE,gCAAgC,KAAK;EAC7E,OAAO;GACN,OAAO,MAAM,WAAW,MAAM;GAC9B,MAAM,MAAM,WAAW;GACvB,QAAQ,MAAM;GACd,QAAQ,MAAM;GACd,KAAK,MAAM;GACX,OAAO,MAAM;GACb,MAAM,MAAM;GACZ,OAAO,MAAM,UAAU,WAAW,WAAW;EAC9C;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"issueWrites.js","names":[],"sources":["../../../../../plus/git-github/src/api/issueWrites.ts"],"sourcesContent":["import { GraphqlResponseError } from '@octokit/graphql';\nimport { RequestError } from '@octokit/request-error';\nimport type { RequestParameters } from '@octokit/types';\nimport { RequestRateLimitError } from '@gitlens/git/errors.js';\n\ntype GitHubIssueWriteTarget = { owner: string; repo: string };\n\nexport type GitHubIssueDelete = GitHubIssueWriteTarget & { number: number; expectedNodeId: string };\n\nexport type GitHubIssueWrite =\n\t| (GitHubIssueWriteTarget & { action: 'create'; title: string; body?: string })\n\t| (GitHubIssueDelete &\n\t\t\t(\n\t\t\t\t| { action: 'edit'; title?: string; body?: string }\n\t\t\t\t| { action: 'set-state'; state: 'open' }\n\t\t\t\t| { action: 'set-state'; state: 'closed'; reason: 'completed' | 'not_planned' }\n\t\t\t));\n\nexport type IssueWriteResult =\n\t| {\n\t\t\tok: true;\n\t\t\tissue: {\n\t\t\t\towner: string;\n\t\t\t\trepo: string;\n\t\t\t\tnumber: number;\n\t\t\t\tnodeId: string;\n\t\t\t\turl: string;\n\t\t\t\ttitle: string;\n\t\t\t\tbody: string;\n\t\t\t\tstate: 'open' | 'closed';\n\t\t\t};\n\t\t\tdeletedFromDifferentRepository?: true;\n\t }\n\t| {\n\t\t\tok: false;\n\t\t\treason:\n\t\t\t\t| 'unsupported'\n\t\t\t\t| 'no-connection'\n\t\t\t\t| 'forbidden'\n\t\t\t\t| 'not-found'\n\t\t\t\t| 'invalid-input'\n\t\t\t\t| 'rate-limit'\n\t\t\t\t| 'unknown';\n\t\t\t/** An unconfirmed result that failed before the mutation could be sent. */\n\t\t\tmutationDispatched?: false;\n\t };\n\nexport type GitHubIssueMutation =\n\t| GitHubIssueWrite\n\t| (GitHubIssueDelete & { action: 'delete' })\n\t| (GitHubIssueDelete & { action: 'resolve'; intent?: 'delete' });\ntype GraphqlRequest = <T>(query: string, variables: RequestParameters) => Promise<T | undefined>;\n\nconst issueFields = `\n\tid number url title body state\n\trepository { id owner { login } name }\n`;\n\ntype IssueNode = {\n\tid: string;\n\tnumber: number;\n\turl: string;\n\ttitle: string;\n\tbody: string;\n\tstate: 'OPEN' | 'CLOSED';\n\trepository: { id: string; owner: { login: string }; name: string };\n};\n\ntype RepositoryNode = {\n\tid: string;\n\thasIssuesEnabled: boolean;\n\tisArchived: boolean;\n};\n\ntype WriteTarget = {\n\trepository: RepositoryNode | null;\n\tnode?: (IssueNode & { __typename: string; viewerCanDelete?: boolean }) | null;\n};\n\nexport function isValidGitHubIssueMutation(input: GitHubIssueMutation): boolean {\n\tif (\n\t\ttypeof input.owner !== 'string' ||\n\t\t!/^[a-z\\d_-]+$/i.test(input.owner) ||\n\t\ttypeof input.repo !== 'string' ||\n\t\t!/^[a-z\\d._-]+$/i.test(input.repo) ||\n\t\tinput.repo === '.' ||\n\t\tinput.repo === '..'\n\t) {\n\t\treturn false;\n\t}\n\n\tif (\n\t\tinput.action !== 'create' &&\n\t\t(!Number.isInteger(input.number) ||\n\t\t\tinput.number < 1 ||\n\t\t\tinput.number > 2147483647 ||\n\t\t\ttypeof input.expectedNodeId !== 'string' ||\n\t\t\t!input.expectedNodeId.trim())\n\t) {\n\t\treturn false;\n\t}\n\n\tswitch (input.action) {\n\t\tcase 'create':\n\t\t\treturn isIssueTitle(input.title) && (input.body === undefined || typeof input.body === 'string');\n\t\tcase 'edit':\n\t\t\treturn (\n\t\t\t\t(input.title !== undefined || input.body !== undefined) &&\n\t\t\t\t(input.title === undefined || isIssueTitle(input.title)) &&\n\t\t\t\t(input.body === undefined || typeof input.body === 'string')\n\t\t\t);\n\t\tcase 'set-state':\n\t\t\treturn (\n\t\t\t\tinput.state === 'open' ||\n\t\t\t\t(input.state === 'closed' && (input.reason === 'completed' || input.reason === 'not_planned'))\n\t\t\t);\n\t\tcase 'delete':\n\t\t\treturn true;\n\t\tcase 'resolve':\n\t\t\treturn input.intent === undefined || input.intent === 'delete';\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction isIssueTitle(title: unknown): title is string {\n\treturn typeof title === 'string' && title.trim().length > 0;\n}\n\nexport function issueWriteFailure(ex: unknown): Extract<IssueWriteResult, { ok: false }> {\n\tif (RequestRateLimitError.is(ex)) return { ok: false, reason: 'rate-limit' };\n\n\tif (ex instanceof GraphqlResponseError) {\n\t\tif (ex.errors?.some(error => error.type === 'RATE_LIMIT' || error.type === 'RATE_LIMITED')) {\n\t\t\treturn { ok: false, reason: 'rate-limit' };\n\t\t}\n\n\t\tswitch (ex.errors?.[0]?.type) {\n\t\t\tcase 'NOT_FOUND':\n\t\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t\tcase 'FORBIDDEN':\n\t\t\tcase 'INSUFFICIENT_SCOPES':\n\t\t\t\treturn { ok: false, reason: 'forbidden' };\n\t\t\tcase 'BAD_USER_INPUT':\n\t\t\tcase 'UNPROCESSABLE':\n\t\t\t\treturn { ok: false, reason: 'invalid-input' };\n\t\t}\n\t}\n\n\tif (ex instanceof RequestError) {\n\t\tswitch (ex.status) {\n\t\t\tcase 400:\n\t\t\tcase 422:\n\t\t\t\treturn { ok: false, reason: 'invalid-input' };\n\t\t\tcase 401:\n\t\t\t\treturn { ok: false, reason: 'no-connection' };\n\t\t\tcase 403:\n\t\t\t\treturn {\n\t\t\t\t\tok: false,\n\t\t\t\t\treason: ex.message.toLowerCase().includes('rate limit') ? 'rate-limit' : 'forbidden',\n\t\t\t\t};\n\t\t\tcase 404:\n\t\t\tcase 410:\n\t\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t\tcase 429:\n\t\t\t\treturn { ok: false, reason: 'rate-limit' };\n\t\t}\n\t}\n\n\treturn { ok: false, reason: 'unknown' };\n}\n\nexport async function mutateGitHubIssue(\n\tinput: GitHubIssueMutation,\n\tgraphql: GraphqlRequest,\n\t{ origin, isSessionCurrent }: { origin?: string; isSessionCurrent?: () => Promise<boolean> },\n): Promise<IssueWriteResult> {\n\tlet dispatched = false;\n\tconst mutate: GraphqlRequest = (query, variables) => {\n\t\tdispatched = true;\n\t\treturn graphql(query, variables);\n\t};\n\ttry {\n\t\tconst { owner, repo } = input;\n\t\tconst checkDelete = input.action === 'delete' || (input.action === 'resolve' && input.intent === 'delete');\n\t\tconst target =\n\t\t\tinput.action === 'create'\n\t\t\t\t? await graphql<WriteTarget>(\n\t\t\t\t\t\t`\n\t\t\t\t\t\t\tquery IssueCreateTarget($owner: String!, $repo: String!) {\n\t\t\t\t\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\t\t\thasIssuesEnabled\n\t\t\t\t\t\t\t\t\tisArchived\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t`,\n\t\t\t\t\t\t{ owner: owner, repo: repo },\n\t\t\t\t\t)\n\t\t\t\t: await graphql<WriteTarget>(\n\t\t\t\t\t\t`query IssueWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID!) {\n\t\t\t\t\t\t\trepository(owner: $owner, name: $repo, followRenames: false) {\n\t\t\t\t\t\t\t\tid hasIssuesEnabled isArchived\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tnode(id: $expectedNodeId) {\n\t\t\t\t\t\t\t\t__typename\n\t\t\t\t\t\t\t\t... on Issue {\n\t\t\t\t\t\t\t\t\t${issueFields}\n\t\t\t\t\t\t\t\t\t${checkDelete ? 'viewerCanDelete' : ''}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\towner: owner,\n\t\t\t\t\t\t\trepo: repo,\n\t\t\t\t\t\t\texpectedNodeId: input.expectedNodeId,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\tconst repository = target?.repository;\n\t\tif (repository == null) return { ok: false, reason: 'not-found' };\n\t\tif (repository.isArchived) return { ok: false, reason: 'forbidden' };\n\t\tif (!repository.hasIssuesEnabled) return { ok: false, reason: 'unsupported' };\n\n\t\tif (input.action === 'create') {\n\t\t\tif (isSessionCurrent != null && !(await isSessionCurrent())) {\n\t\t\t\treturn { ok: false, reason: 'no-connection' };\n\t\t\t}\n\n\t\t\treturn await writeIssue(\n\t\t\t\tmutate,\n\t\t\t\t'createIssue',\n\t\t\t\t'CreateIssueInput',\n\t\t\t\t{\n\t\t\t\t\trepositoryId: repository.id,\n\t\t\t\t\ttitle: input.title,\n\t\t\t\t\tbody: input.body,\n\t\t\t\t},\n\t\t\t\torigin,\n\t\t\t);\n\t\t}\n\n\t\tconst issue = target?.node;\n\t\tif (\n\t\t\tissue?.__typename !== 'Issue' ||\n\t\t\t!isGitHubWriteUrlOnInstallation(issue.url, origin) ||\n\t\t\tissue.number !== input.number ||\n\t\t\tissue.repository.id !== repository.id ||\n\t\t\tissue.repository.owner.login.toLowerCase() !== owner.toLowerCase() ||\n\t\t\tissue.repository.name.toLowerCase() !== repo.toLowerCase()\n\t\t) {\n\t\t\treturn { ok: false, reason: 'not-found' };\n\t\t}\n\n\t\tif (checkDelete && issue.viewerCanDelete !== true) return { ok: false, reason: 'forbidden' };\n\n\t\tif (input.action === 'resolve') return toIssueWriteResult(issue);\n\n\t\tif (isSessionCurrent != null && !(await isSessionCurrent())) {\n\t\t\treturn { ok: false, reason: 'no-connection' };\n\t\t}\n\n\t\tswitch (input.action) {\n\t\t\tcase 'edit':\n\t\t\t\treturn await writeIssue(\n\t\t\t\t\tmutate,\n\t\t\t\t\t'updateIssue',\n\t\t\t\t\t'UpdateIssueInput',\n\t\t\t\t\t{\n\t\t\t\t\t\tid: issue.id,\n\t\t\t\t\t\ttitle: input.title,\n\t\t\t\t\t\tbody: input.body,\n\t\t\t\t\t},\n\t\t\t\t\torigin,\n\t\t\t\t);\n\t\t\tcase 'set-state':\n\t\t\t\treturn input.state === 'open'\n\t\t\t\t\t? await writeIssue(mutate, 'reopenIssue', 'ReopenIssueInput', { issueId: issue.id }, origin)\n\t\t\t\t\t: await writeIssue(\n\t\t\t\t\t\t\tmutate,\n\t\t\t\t\t\t\t'closeIssue',\n\t\t\t\t\t\t\t'CloseIssueInput',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tissueId: issue.id,\n\t\t\t\t\t\t\t\tstateReason: input.reason === 'completed' ? 'COMPLETED' : 'NOT_PLANNED',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\torigin,\n\t\t\t\t\t\t);\n\t\t\tcase 'delete': {\n\t\t\t\tconst result = await mutate<{ deleteIssue: { repository: { id: string } | null } | null }>(\n\t\t\t\t\t`\n\t\t\t\t\t\tmutation DeleteIssue($issueId: ID!) {\n\t\t\t\t\t\t\tdeleteIssue(input: { issueId: $issueId }) {\n\t\t\t\t\t\t\t\trepository {\n\t\t\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t`,\n\t\t\t\t\t{ issueId: issue.id },\n\t\t\t\t);\n\t\t\t\tconst deletedRepositoryId = result?.deleteIssue?.repository?.id;\n\t\t\t\treturn typeof deletedRepositoryId === 'string' && deletedRepositoryId.length > 0\n\t\t\t\t\t? toIssueWriteResult(issue, deletedRepositoryId !== repository.id)\n\t\t\t\t\t: { ok: false, reason: 'unknown' };\n\t\t\t}\n\t\t}\n\t} catch (ex) {\n\t\tif (\n\t\t\torigin != null &&\n\t\t\tex instanceof GraphqlResponseError &&\n\t\t\tex.data == null &&\n\t\t\tex.errors?.some(error => {\n\t\t\t\tconst code: unknown = error.extensions?.code;\n\t\t\t\treturn (\n\t\t\t\t\tcode === 'undefinedField' || code === 'argumentNotAccepted' || code === 'variableRequiresValidType'\n\t\t\t\t);\n\t\t\t})\n\t\t) {\n\t\t\treturn { ok: false, reason: 'unsupported' };\n\t\t}\n\n\t\tif (\n\t\t\tdispatched &&\n\t\t\tex instanceof GraphqlResponseError &&\n\t\t\tex.errors?.some(error => error.path != null && error.path.length > 1)\n\t\t) {\n\t\t\treturn { ok: false, reason: 'unknown' };\n\t\t}\n\n\t\tconst failure = issueWriteFailure(ex);\n\t\treturn origin != null && failure.reason === 'unknown' && !dispatched\n\t\t\t? { ...failure, mutationDispatched: false }\n\t\t\t: failure;\n\t}\n}\n\nasync function writeIssue(\n\tgraphql: GraphqlRequest,\n\tmutation: 'createIssue' | 'updateIssue' | 'closeIssue' | 'reopenIssue',\n\tinputType: string,\n\tinput: Record<string, string | undefined>,\n\torigin: string | undefined,\n): Promise<IssueWriteResult> {\n\tconst result = await graphql<{ change: { issue: IssueNode | null } | null }>(\n\t\t`mutation WriteIssue($input: ${inputType}!) {\n\t\t\tchange: ${mutation}(input: $input) { issue { ${issueFields} } }\n\t\t}`,\n\t\t{ input: input },\n\t);\n\tconst issue = result?.change?.issue;\n\treturn issue != null && isGitHubWriteUrlOnInstallation(issue.url, origin)\n\t\t? toIssueWriteResult(issue)\n\t\t: { ok: false, reason: 'unknown' };\n}\n\nexport function isGitHubWriteUrlOnInstallation(value: unknown, origin: string | undefined): boolean {\n\tif (origin == null) return true;\n\n\tconst url = typeof value === 'string' ? URL.parse(value) : null;\n\treturn (\n\t\turl?.origin === origin &&\n\t\t(url.protocol === 'https:' || url.protocol === 'http:') &&\n\t\t!url.username &&\n\t\t!url.password\n\t);\n}\n\nfunction toIssueWriteResult(issue: IssueNode, deletedFromDifferentRepository = false): IssueWriteResult {\n\treturn {\n\t\tok: true,\n\t\t...(deletedFromDifferentRepository && { deletedFromDifferentRepository: true }),\n\t\tissue: {\n\t\t\towner: issue.repository.owner.login,\n\t\t\trepo: issue.repository.name,\n\t\t\tnumber: issue.number,\n\t\t\tnodeId: issue.id,\n\t\t\turl: issue.url,\n\t\t\ttitle: issue.title,\n\t\t\tbody: issue.body,\n\t\t\tstate: issue.state === 'CLOSED' ? 'closed' : 'open',\n\t\t},\n\t};\n}\n"],"mappings":";;;;AAqDA,MAAM,cAAc;;;;AA0BpB,SAAgB,2BAA2B,OAAqC;CAC/E,IACC,OAAO,MAAM,UAAU,YACvB,CAAC,gBAAgB,KAAK,MAAM,KAAK,KACjC,OAAO,MAAM,SAAS,YACtB,CAAC,iBAAiB,KAAK,MAAM,IAAI,KACjC,MAAM,SAAS,OACf,MAAM,SAAS,MAEf,OAAO;CAGR,IACC,MAAM,WAAW,aAChB,CAAC,OAAO,UAAU,MAAM,MAAM,KAC9B,MAAM,SAAS,KACf,MAAM,SAAS,cACf,OAAO,MAAM,mBAAmB,YAChC,CAAC,MAAM,eAAe,KAAK,IAE5B,OAAO;CAGR,QAAQ,MAAM,QAAd;EACC,KAAK,UACJ,OAAO,aA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
|
2
|
-
import {
|
|
2
|
+
import { EnterprisePullRequestWriteOptions, GraphqlRequest } from "./enterprisePullRequestMergePolicy.js";
|
|
3
3
|
//#region ../plus/git-github/src/api/pullRequestWrites.d.ts
|
|
4
4
|
type MergeMethod = `${PullRequestMergeMethod}`;
|
|
5
5
|
export type GitHubPullRequestCreateTarget = {
|
|
@@ -38,6 +38,8 @@ export type PullRequestWriteFailure = {
|
|
|
38
38
|
reason: 'unsupported' | 'no-connection' | 'forbidden' | 'not-found' | 'invalid-input' | 'rate-limit' | 'blocked' | 'head-changed' | 'base-changed' | 'unknown' | 'outcome-unknown';
|
|
39
39
|
};
|
|
40
40
|
export type PullRequestWriteSnapshot = {
|
|
41
|
+
/** The installation origin for GitHub Enterprise Server pull requests. */
|
|
42
|
+
domain?: string;
|
|
41
43
|
owner: string;
|
|
42
44
|
repo: string;
|
|
43
45
|
number: number;
|
|
@@ -80,13 +82,15 @@ export type PullRequestWriteResult = {
|
|
|
80
82
|
ok: true;
|
|
81
83
|
status: 'created' | 'updated' | 'closed' | 'reopened' | 'merged' | 'queued';
|
|
82
84
|
pullRequest: PullRequestWriteSnapshot;
|
|
85
|
+
/** The result is confirmed, but its snapshot belongs to a replaced or disconnected credential. */
|
|
86
|
+
credentialChanged?: true;
|
|
83
87
|
} | PullRequestWriteFailure;
|
|
84
|
-
type GraphqlRequest = <T>(query: string, variables: RequestParameters) => Promise<T | undefined>;
|
|
85
88
|
export declare function pullRequestWriteFailure(ex: unknown, phase?: 'write' | 'merge' | 'enqueue'): PullRequestWriteFailure;
|
|
86
|
-
export declare function resolveGitHubPullRequestWriteTarget(input: GitHubPullRequestWriteTarget, graphql: GraphqlRequest): Promise<PullRequestWriteTargetResult>;
|
|
89
|
+
export declare function resolveGitHubPullRequestWriteTarget(input: GitHubPullRequestWriteTarget, graphql: GraphqlRequest, enterprise?: EnterprisePullRequestWriteOptions): Promise<PullRequestWriteTargetResult>;
|
|
87
90
|
export declare function getGitHubPullRequestCreateCapability(input: GitHubPullRequestCreateTarget, graphql: GraphqlRequest): Promise<PullRequestCreateCapabilityResult>;
|
|
88
91
|
type WriteTransport = {
|
|
89
92
|
graphql: GraphqlRequest;
|
|
93
|
+
enterprise?: EnterprisePullRequestWriteOptions;
|
|
90
94
|
isSessionCurrent: () => Promise<boolean>;
|
|
91
95
|
enqueue: (nodeId: string, headSha: string) => Promise<PullRequestMergeQueueActionResult>;
|
|
92
96
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AuthenticationError, RequestNotFoundError } from "../../../git/errors.js";
|
|
2
|
-
import { issueWriteFailure } from "./issueWrites.js";
|
|
2
|
+
import { isGitHubWriteUrlOnInstallation, issueWriteFailure } from "./issueWrites.js";
|
|
3
|
+
import { readEnterprisePullRequestMergePolicy } from "./enterprisePullRequestMergePolicy.js";
|
|
3
4
|
import { GraphqlResponseError } from "@octokit/graphql";
|
|
4
5
|
//#region ../plus/git-github/src/api/pullRequestWrites.ts
|
|
5
6
|
const repositoryIdentity = "id owner { login } name";
|
|
@@ -81,7 +82,7 @@ function isRepositoryWritable(repository) {
|
|
|
81
82
|
function sameRepository(a, b) {
|
|
82
83
|
return a.owner.toLowerCase() === b.owner.login.toLowerCase() && a.repo.toLowerCase() === b.name.toLowerCase();
|
|
83
84
|
}
|
|
84
|
-
function toSnapshot(node) {
|
|
85
|
+
function toSnapshot(node, origin) {
|
|
85
86
|
const closedAt = node.state === "MERGED" ? node.mergedAt ?? node.closedAt : node.closedAt;
|
|
86
87
|
return {
|
|
87
88
|
owner: node.repository.owner.login,
|
|
@@ -89,6 +90,7 @@ function toSnapshot(node) {
|
|
|
89
90
|
number: node.number,
|
|
90
91
|
nodeId: node.id,
|
|
91
92
|
url: node.url,
|
|
93
|
+
...origin != null && { domain: origin },
|
|
92
94
|
title: node.title,
|
|
93
95
|
body: node.body,
|
|
94
96
|
state: node.state === "OPEN" ? "open" : node.state === "CLOSED" ? "closed" : "merged",
|
|
@@ -98,21 +100,20 @@ function toSnapshot(node) {
|
|
|
98
100
|
baseRef: node.baseRefName
|
|
99
101
|
};
|
|
100
102
|
}
|
|
101
|
-
async function resolveNode(input, graphql) {
|
|
103
|
+
async function resolveNode(input, graphql, origin) {
|
|
102
104
|
const { owner, repo, expectedNodeId, number } = input;
|
|
103
105
|
const result = await graphql(`query PullRequestWriteTarget($owner: String!, $repo: String!, $expectedNodeId: ID!) {
|
|
104
106
|
repository(owner: $owner, name: $repo, followRenames: false) {
|
|
105
107
|
${repositoryFields}
|
|
106
|
-
mergeCommitAllowed squashMergeAllowed rebaseMergeAllowed viewerDefaultMergeMethod
|
|
108
|
+
mergeCommitAllowed squashMergeAllowed rebaseMergeAllowed ${origin == null ? "viewerDefaultMergeMethod" : ""}
|
|
107
109
|
}
|
|
108
110
|
node(id: $expectedNodeId) {
|
|
109
111
|
__typename
|
|
110
112
|
... on PullRequest {
|
|
111
113
|
${pullRequestFields}
|
|
112
114
|
viewerCanUpdate viewerCanClose viewerCanReopen
|
|
113
|
-
isDraft
|
|
114
|
-
stack { id }
|
|
115
|
-
baseRef { id }
|
|
115
|
+
isDraft baseRef { id }
|
|
116
|
+
${origin == null ? "isInMergeQueue isMergeQueueEnabled stack { id }" : ""}
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
}`, {
|
|
@@ -122,7 +123,7 @@ async function resolveNode(input, graphql) {
|
|
|
122
123
|
});
|
|
123
124
|
const repository = result?.repository;
|
|
124
125
|
const node = result?.node;
|
|
125
|
-
if (repository == null || !sameRepository(input, repository) || node?.__typename !== "PullRequest" || node.number !== number || node.repository.id !== repository.id) return {
|
|
126
|
+
if (repository == null || !sameRepository(input, repository) || node?.__typename !== "PullRequest" || node.number !== number || node.repository.id !== repository.id || !sameRepository(input, node.repository) || !isGitHubWriteUrlOnInstallation(node.url, origin)) return {
|
|
126
127
|
ok: false,
|
|
127
128
|
reason: "not-found"
|
|
128
129
|
};
|
|
@@ -184,7 +185,8 @@ async function readBranchRules(refId, graphql) {
|
|
|
184
185
|
cursor = nextCursor;
|
|
185
186
|
}
|
|
186
187
|
}
|
|
187
|
-
async function getMergeCapability(
|
|
188
|
+
async function getMergeCapability(resolved, graphql, enterprise) {
|
|
189
|
+
const { node, repository } = resolved;
|
|
188
190
|
if (!isRepositoryWritable(repository) || node.state !== "OPEN" || node.isDraft || node.isInMergeQueue || node.baseRef == null) return {
|
|
189
191
|
kind: "unavailable",
|
|
190
192
|
reason: "blocked"
|
|
@@ -200,30 +202,24 @@ async function getMergeCapability({ node, repository }, graphql) {
|
|
|
200
202
|
};
|
|
201
203
|
if (node.isMergeQueueEnabled) return { kind: "queue" };
|
|
202
204
|
try {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
+
if (enterprise != null) {
|
|
206
|
+
const policy = await readEnterprisePullRequestMergePolicy({
|
|
207
|
+
id: node.id,
|
|
208
|
+
baseRef: node.baseRefName,
|
|
209
|
+
baseRefId: node.baseRef.id
|
|
210
|
+
}, {
|
|
211
|
+
owner: repository.owner.login,
|
|
212
|
+
repo: repository.name
|
|
213
|
+
}, graphql, enterprise.readBranchRules);
|
|
214
|
+
return "kind" in policy ? policy : getDirectMergeCapability(repository, policy);
|
|
215
|
+
}
|
|
216
|
+
const policy = await readBranchRules(node.baseRef.id, graphql);
|
|
217
|
+
if (policy == null) return {
|
|
205
218
|
kind: "unavailable",
|
|
206
219
|
reason: "unknown"
|
|
207
220
|
};
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const linearHistory = requiresLinearHistory || rules.some((rule) => rule.type === "REQUIRED_LINEAR_HISTORY");
|
|
211
|
-
const methods = mergeMethods.filter((method) => {
|
|
212
|
-
return (method === "merge" ? repository.mergeCommitAllowed && !linearHistory : method === "squash" ? repository.squashMergeAllowed : repository.rebaseMergeAllowed) && rules.every((rule) => {
|
|
213
|
-
const permitted = rule.type === "PULL_REQUEST" ? rule.parameters?.allowedMergeMethods : void 0;
|
|
214
|
-
return permitted == null || permitted.some((allowedMethod) => allowedMethod.toLowerCase() === method);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
if (methods.length === 0) return {
|
|
218
|
-
kind: "unavailable",
|
|
219
|
-
reason: "blocked"
|
|
220
|
-
};
|
|
221
|
-
const preference = repository.viewerDefaultMergeMethod.toLowerCase();
|
|
222
|
-
return {
|
|
223
|
-
kind: "direct",
|
|
224
|
-
methods,
|
|
225
|
-
defaultMethod: methods.find((method) => method === preference)
|
|
226
|
-
};
|
|
221
|
+
if (policy.rules.some((rule) => rule.type === "MERGE_QUEUE")) return { kind: "queue" };
|
|
222
|
+
return getDirectMergeCapability(repository, policy);
|
|
227
223
|
} catch (ex) {
|
|
228
224
|
return {
|
|
229
225
|
kind: "unavailable",
|
|
@@ -231,24 +227,43 @@ async function getMergeCapability({ node, repository }, graphql) {
|
|
|
231
227
|
};
|
|
232
228
|
}
|
|
233
229
|
}
|
|
234
|
-
|
|
230
|
+
function getDirectMergeCapability(repository, { rules, requiresLinearHistory }) {
|
|
231
|
+
const linearHistory = requiresLinearHistory || rules.some((rule) => rule.type === "REQUIRED_LINEAR_HISTORY");
|
|
232
|
+
const methods = mergeMethods.filter((method) => {
|
|
233
|
+
return (method === "merge" ? repository.mergeCommitAllowed && !linearHistory : method === "squash" ? repository.squashMergeAllowed : repository.rebaseMergeAllowed) && rules.every((rule) => {
|
|
234
|
+
const permitted = rule.type === "PULL_REQUEST" ? rule.parameters?.allowedMergeMethods : void 0;
|
|
235
|
+
return permitted == null || permitted.some((allowedMethod) => allowedMethod.toLowerCase() === method);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
if (methods.length === 0) return {
|
|
239
|
+
kind: "unavailable",
|
|
240
|
+
reason: "blocked"
|
|
241
|
+
};
|
|
242
|
+
const preference = repository.viewerDefaultMergeMethod?.toLowerCase();
|
|
243
|
+
return {
|
|
244
|
+
kind: "direct",
|
|
245
|
+
methods,
|
|
246
|
+
defaultMethod: methods.find((method) => method === preference)
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
async function resolveGitHubPullRequestWriteTarget(input, graphql, enterprise) {
|
|
235
250
|
if (!isValidTarget(input)) return {
|
|
236
251
|
ok: false,
|
|
237
252
|
reason: "invalid-input"
|
|
238
253
|
};
|
|
239
254
|
try {
|
|
240
|
-
const resolved = await resolveNode(input, graphql);
|
|
255
|
+
const resolved = await resolveNode(input, graphql, enterprise?.origin);
|
|
241
256
|
if (!resolved.ok) return resolved;
|
|
242
257
|
const { node, repository } = resolved;
|
|
243
258
|
const writable = isRepositoryWritable(repository);
|
|
244
259
|
return {
|
|
245
260
|
ok: true,
|
|
246
|
-
pullRequest: toSnapshot(node),
|
|
261
|
+
pullRequest: toSnapshot(node, enterprise?.origin),
|
|
247
262
|
capabilities: {
|
|
248
263
|
edit: writable && node.viewerCanUpdate,
|
|
249
264
|
close: writable && node.state === "OPEN" && node.viewerCanClose,
|
|
250
265
|
reopen: writable && node.state === "CLOSED" && node.viewerCanReopen,
|
|
251
|
-
merge: await getMergeCapability(resolved, graphql)
|
|
266
|
+
merge: await getMergeCapability(resolved, graphql, enterprise)
|
|
252
267
|
}
|
|
253
268
|
};
|
|
254
269
|
} catch (ex) {
|
|
@@ -287,38 +302,55 @@ const mutations = {
|
|
|
287
302
|
updated: ["updatePullRequest", "UpdatePullRequestInput"],
|
|
288
303
|
closed: ["closePullRequest", "ClosePullRequestInput"],
|
|
289
304
|
reopened: ["reopenPullRequest", "ReopenPullRequestInput"],
|
|
290
|
-
merged: ["mergePullRequest", "MergePullRequestInput"]
|
|
305
|
+
merged: ["mergePullRequest", "MergePullRequestInput"],
|
|
306
|
+
queued: ["enqueuePullRequest", "EnqueuePullRequestInput"]
|
|
291
307
|
};
|
|
292
|
-
async function sendMutation(transport, status,
|
|
308
|
+
async function sendMutation(transport, status, repository, values, previous) {
|
|
293
309
|
if (!await transport.isSessionCurrent()) return {
|
|
294
310
|
ok: false,
|
|
295
311
|
reason: "no-connection"
|
|
296
312
|
};
|
|
297
313
|
const [mutation, inputType] = mutations[status];
|
|
298
|
-
|
|
314
|
+
const pullRequest = `pullRequest { ${status === "created" && transport.enterprise?.origin != null ? `${pullRequestFields} headRefName` : pullRequestFields} }`;
|
|
315
|
+
const selection = status === "queued" ? `mergeQueueEntry { id ${pullRequest} }` : pullRequest;
|
|
316
|
+
let payload;
|
|
317
|
+
let error;
|
|
299
318
|
try {
|
|
300
|
-
|
|
301
|
-
change: ${mutation}(input: $input) {
|
|
302
|
-
}`, { input: values })
|
|
319
|
+
payload = await transport.graphql(`mutation WritePullRequest($input: ${inputType}!) {
|
|
320
|
+
change: ${mutation}(input: $input) { ${selection} }
|
|
321
|
+
}`, { input: values });
|
|
303
322
|
} catch (ex) {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
if (node == null && ex.errors?.some((error) => error.path?.[0] === "change" && error.path.length > 1)) return {
|
|
307
|
-
ok: false,
|
|
308
|
-
reason: "outcome-unknown"
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
if (node == null) return pullRequestWriteFailure(ex, status === "merged" ? "merge" : "write");
|
|
323
|
+
error = ex;
|
|
324
|
+
if (ex instanceof GraphqlResponseError) payload = ex.data;
|
|
312
325
|
}
|
|
313
|
-
const
|
|
314
|
-
|
|
326
|
+
const entry = payload?.change?.mergeQueueEntry;
|
|
327
|
+
const node = status === "queued" ? typeof entry?.id === "string" && entry.id ? entry.pullRequest : void 0 : payload?.change?.pullRequest;
|
|
328
|
+
if (node == null && error != null) {
|
|
329
|
+
if (error instanceof GraphqlResponseError && error.errors?.some((item) => item.path?.[0] === "change" && item.path.length > 1)) return {
|
|
330
|
+
ok: false,
|
|
331
|
+
reason: "outcome-unknown"
|
|
332
|
+
};
|
|
333
|
+
return pullRequestWriteFailure(error, status === "merged" ? "merge" : status === "queued" ? "enqueue" : "write");
|
|
334
|
+
}
|
|
335
|
+
const expectedState = status === "created" || status === "reopened" || status === "queued" ? "OPEN" : status === "closed" ? "CLOSED" : status === "merged" ? "MERGED" : void 0;
|
|
336
|
+
if (node?.repository?.id !== repository.id || previous != null && (node.id !== previous.id || node.number !== previous.number) || expectedState != null && node.state !== expectedState || typeof node.repository.owner?.login !== "string" || typeof node.repository.name !== "string" || typeof node.id !== "string" || !Number.isInteger(node.number) || typeof node.url !== "string" || typeof node.title !== "string" || typeof node.body !== "string" || typeof node.headRefOid !== "string" || typeof node.baseRefName !== "string" || !isGitHubWriteUrlOnInstallation(node.url, transport.enterprise?.origin) || node.state !== "OPEN" && node.state !== "CLOSED" && node.state !== "MERGED") return {
|
|
315
337
|
ok: false,
|
|
316
338
|
reason: "outcome-unknown"
|
|
317
339
|
};
|
|
340
|
+
if (transport.enterprise?.origin != null) {
|
|
341
|
+
if (status === "created" && (node.baseRefName !== values.baseRefName || node.headRefName !== values.headRefName)) return {
|
|
342
|
+
ok: false,
|
|
343
|
+
reason: "outcome-unknown"
|
|
344
|
+
};
|
|
345
|
+
if ((status === "merged" || status === "queued") && (node.baseRefName !== previous?.baseRefName || node.headRefOid.toLowerCase() !== previous.headRefOid.toLowerCase())) return {
|
|
346
|
+
ok: false,
|
|
347
|
+
reason: "outcome-unknown"
|
|
348
|
+
};
|
|
349
|
+
}
|
|
318
350
|
return {
|
|
319
351
|
ok: true,
|
|
320
352
|
status,
|
|
321
|
-
pullRequest: toSnapshot(node)
|
|
353
|
+
pullRequest: toSnapshot(node, transport.enterprise?.origin)
|
|
322
354
|
};
|
|
323
355
|
}
|
|
324
356
|
async function createPullRequest(input, transport) {
|
|
@@ -346,7 +378,7 @@ async function createPullRequest(input, transport) {
|
|
|
346
378
|
ok: false,
|
|
347
379
|
reason: "invalid-input"
|
|
348
380
|
};
|
|
349
|
-
return sendMutation(transport, "created", repository
|
|
381
|
+
return sendMutation(transport, "created", repository, {
|
|
350
382
|
repositoryId: repository.id,
|
|
351
383
|
baseRefName: input.baseRef,
|
|
352
384
|
headRefName: input.headRef,
|
|
@@ -364,26 +396,47 @@ async function mergePullRequest(input, resolved, transport) {
|
|
|
364
396
|
ok: false,
|
|
365
397
|
reason: "base-changed"
|
|
366
398
|
};
|
|
367
|
-
const capability = await getMergeCapability(resolved, transport.graphql);
|
|
399
|
+
const capability = await getMergeCapability(resolved, transport.graphql, transport.enterprise);
|
|
368
400
|
if (capability.kind === "unavailable") return {
|
|
369
401
|
ok: false,
|
|
370
402
|
reason: capability.reason
|
|
371
403
|
};
|
|
372
|
-
if (input.action === "merge") {
|
|
373
|
-
|
|
404
|
+
if (input.action === "merge" ? capability.kind !== "direct" || !capability.methods.includes(input.mergeMethod) : capability.kind !== "queue") return {
|
|
405
|
+
ok: false,
|
|
406
|
+
reason: "blocked"
|
|
407
|
+
};
|
|
408
|
+
if (transport.enterprise?.origin != null) {
|
|
409
|
+
const current = await resolveNode({
|
|
410
|
+
...input,
|
|
411
|
+
expectedNodeId: node.id
|
|
412
|
+
}, transport.graphql, transport.enterprise.origin);
|
|
413
|
+
if (!current.ok) return current;
|
|
414
|
+
if (current.node.id !== node.id || current.repository.id !== repository.id) return {
|
|
415
|
+
ok: false,
|
|
416
|
+
reason: "not-found"
|
|
417
|
+
};
|
|
418
|
+
if (current.node.baseRefName !== input.expectedBaseRef || current.node.baseRef?.id !== node.baseRef?.id) return {
|
|
419
|
+
ok: false,
|
|
420
|
+
reason: "base-changed"
|
|
421
|
+
};
|
|
422
|
+
if (current.node.headRefOid.toLowerCase() !== input.expectedHeadSha.toLowerCase()) return {
|
|
423
|
+
ok: false,
|
|
424
|
+
reason: "head-changed"
|
|
425
|
+
};
|
|
426
|
+
if (current.node.state !== "OPEN" || current.node.isDraft || !isRepositoryWritable(current.repository)) return {
|
|
374
427
|
ok: false,
|
|
375
428
|
reason: "blocked"
|
|
376
429
|
};
|
|
377
|
-
return sendMutation(transport, "merged", repository.id, {
|
|
378
|
-
pullRequestId: node.id,
|
|
379
|
-
expectedHeadOid: node.headRefOid,
|
|
380
|
-
mergeMethod: input.mergeMethod.toUpperCase()
|
|
381
|
-
}, node);
|
|
382
430
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
431
|
+
const values = {
|
|
432
|
+
pullRequestId: node.id,
|
|
433
|
+
expectedHeadOid: node.headRefOid
|
|
386
434
|
};
|
|
435
|
+
if (input.action === "merge") return sendMutation(transport, "merged", repository, {
|
|
436
|
+
...values,
|
|
437
|
+
mergeMethod: input.mergeMethod.toUpperCase()
|
|
438
|
+
}, node);
|
|
439
|
+
if (transport.enterprise?.origin != null) return sendMutation(transport, "queued", repository, values, node);
|
|
387
440
|
if (!await transport.isSessionCurrent()) return {
|
|
388
441
|
ok: false,
|
|
389
442
|
reason: "no-connection"
|
|
@@ -424,13 +477,13 @@ async function mergePullRequest(input, resolved, transport) {
|
|
|
424
477
|
}
|
|
425
478
|
}
|
|
426
479
|
async function writeGitHubPullRequest(input, transport) {
|
|
427
|
-
if (!isValidWrite(input)) return {
|
|
480
|
+
if (!isValidWrite(input) || transport.enterprise?.origin != null && input.action === "create" && input.expectedRepositoryId == null) return {
|
|
428
481
|
ok: false,
|
|
429
482
|
reason: "invalid-input"
|
|
430
483
|
};
|
|
431
484
|
try {
|
|
432
485
|
if (input.action === "create") return await createPullRequest(input, transport);
|
|
433
|
-
const resolved = await resolveNode(input, transport.graphql);
|
|
486
|
+
const resolved = await resolveNode(input, transport.graphql, transport.enterprise?.origin);
|
|
434
487
|
if (!resolved.ok) return resolved;
|
|
435
488
|
const { node, repository } = resolved;
|
|
436
489
|
if (!isRepositoryWritable(repository)) return {
|
|
@@ -443,7 +496,7 @@ async function writeGitHubPullRequest(input, transport) {
|
|
|
443
496
|
ok: false,
|
|
444
497
|
reason: "forbidden"
|
|
445
498
|
};
|
|
446
|
-
return await sendMutation(transport, "updated", repository
|
|
499
|
+
return await sendMutation(transport, "updated", repository, {
|
|
447
500
|
pullRequestId: node.id,
|
|
448
501
|
title: input.title,
|
|
449
502
|
body: input.body
|
|
@@ -458,7 +511,7 @@ async function writeGitHubPullRequest(input, transport) {
|
|
|
458
511
|
ok: false,
|
|
459
512
|
reason: "forbidden"
|
|
460
513
|
};
|
|
461
|
-
return await sendMutation(transport, close ? "closed" : "reopened", repository
|
|
514
|
+
return await sendMutation(transport, close ? "closed" : "reopened", repository, { pullRequestId: node.id }, node);
|
|
462
515
|
} catch (ex) {
|
|
463
516
|
return pullRequestWriteFailure(ex);
|
|
464
517
|
}
|