backport 6.2.0 → 6.3.0-beta-3
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/README.md +15 -6
- package/dist/backportRun.d.ts +2 -2
- package/dist/backportRun.js +13 -8
- package/dist/{entrypoint.api.private.test.d.ts → entrypoint.cli.e2e.private.test.d.ts} +0 -0
- package/dist/entrypoint.cli.e2e.private.test.js +277 -0
- package/dist/entrypoint.cli.js +3 -5
- package/dist/{entrypoint.module.private.test.d.ts → entrypoint.cli.private.test.d.ts} +0 -0
- package/dist/{entrypoint.module.private.test.js → entrypoint.cli.private.test.js} +17 -8
- package/dist/entrypoint.module.d.ts +2 -2
- package/dist/entrypoint.module.js +4 -4
- package/dist/options/ConfigOptions.d.ts +7 -3
- package/dist/options/cliArgs.d.ts +16 -14
- package/dist/options/cliArgs.js +31 -5
- package/dist/options/cliArgs.test.js +28 -10
- package/dist/options/config/config.d.ts +11 -11
- package/dist/options/config/config.js +7 -6
- package/dist/options/config/config.test.js +11 -1
- package/dist/options/config/globalConfig.d.ts +1 -1
- package/dist/options/config/globalConfig.js +15 -9
- package/dist/options/config/globalConfig.test.js +17 -30
- package/dist/options/config/projectConfig.d.ts +3 -1
- package/dist/options/config/projectConfig.js +5 -2
- package/dist/options/config/projectConfig.test.js +41 -31
- package/dist/options/config/readConfigFile.d.ts +21 -23
- package/dist/options/config/readConfigFile.js +2 -2
- package/dist/options/options.d.ts +19 -46
- package/dist/options/options.js +40 -32
- package/dist/options/options.test.js +83 -50
- package/dist/runSequentially.d.ts +0 -1
- package/dist/runSequentially.js +1 -1
- package/dist/runSequentially.test.js +37 -18
- package/dist/scripts/postinstall.js +3 -3
- package/dist/services/HandledError.d.ts +6 -4
- package/dist/services/HandledError.js +18 -3
- package/dist/services/child-process-promisified.d.ts +3 -1
- package/dist/services/env.d.ts +3 -1
- package/dist/services/env.js +4 -1
- package/dist/services/env.test.js +2 -2
- package/dist/services/git.d.ts +22 -9
- package/dist/services/git.integration.test.js +123 -24
- package/dist/services/git.js +66 -54
- package/dist/services/git.test.js +35 -20
- package/dist/services/github/commitFormatters.d.ts +0 -1
- package/dist/services/github/commitFormatters.js +1 -8
- package/dist/services/github/v3/createPullRequest.js +16 -10
- package/dist/services/github/v3/createPullRequest.test.js +248 -33
- package/dist/services/github/v3/createStatusComment.d.ts +1 -1
- package/dist/services/github/v3/createStatusComment.js +26 -15
- package/dist/services/github/v3/createStatusComment.test.js +132 -72
- package/dist/services/github/v3/getGithubV3ErrorMessage.d.ts +2 -1
- package/dist/{options/getValidatedOptions.test.d.ts → services/github/v3/index.d.ts} +0 -0
- package/dist/services/github/v3/index.js +61 -0
- package/dist/services/github/v4/FetchPullRequestId.d.ts +0 -7
- package/dist/services/github/v4/apiRequestV4.d.ts +21 -17
- package/dist/services/github/v4/apiRequestV4.js +46 -28
- package/dist/services/github/v4/apiRequestV4.test.js +4 -4
- package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +0 -7
- package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +0 -7
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +37 -19
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +17 -8
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +3 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +23 -14
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +2 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +4 -4
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +41 -19
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +1 -8
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +31 -14
- package/dist/services/github/v4/fetchExistingPullRequest.d.ts +0 -4
- package/dist/services/github/v4/fetchExistingPullRequest.js +1 -2
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +0 -9
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +7 -9
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +48 -40
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +6 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +15 -23
- package/dist/services/github/v4/getOptionsFromGithub/query.js +17 -25
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +56 -0
- package/dist/{options/parseRequiredOptions.test.d.ts → services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts} +0 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +11 -11
- package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +4 -5
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -7
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +5 -5
- package/dist/services/logger.d.ts +11 -17
- package/dist/services/logger.js +29 -66
- package/dist/services/prompt.test.js +66 -19
- package/dist/services/prompts.js +12 -10
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +1 -1
- package/dist/services/sourceCommit/getMockSourceCommit.js +6 -6
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +18 -10
- package/dist/services/sourceCommit/parseSourceCommit.js +20 -14
- package/dist/services/sourceCommit/parseSourceCommit.test.js +18 -20
- package/dist/{runWithOptions.test.d.ts → test/backport-e2e.mutation.test.d.ts} +0 -0
- package/dist/test/{backport-e2e.private.test.js → backport-e2e.mutation.test.js} +136 -116
- package/dist/test/handleUnbackportedPullRequests.private.test.js +26 -12
- package/dist/test/mockConfigFiles.js +4 -20
- package/dist/test/mocks.d.ts +10 -0
- package/dist/test/mocks.js +23 -0
- package/dist/test/private/getDevAccessToken.js +5 -4
- package/dist/test/sandbox.d.ts +5 -0
- package/dist/{react-components/0-loadOptions.js → test/sandbox.js} +18 -20
- package/dist/test/setupFiles/automatic-mocks.d.ts +1 -0
- package/dist/test/setupFiles/automatic-mocks.js +27 -11
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +12 -13
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +50 -27
- package/dist/ui/getCommits.js +8 -14
- package/dist/ui/getCommitsWithoutBackports.js +6 -6
- package/dist/ui/getCommitsWithoutBackports.test.js +91 -39
- package/dist/ui/getTargetBranches.js +1 -1
- package/dist/ui/getTargetBranches.test.js +26 -8
- package/dist/ui/maybeSetupRepo.js +25 -5
- package/dist/ui/maybeSetupRepo.test.js +144 -18
- package/dist/utils/maybe.d.ts +1 -0
- package/dist/utils/maybe.js +7 -0
- package/dist/utils/packageVersion.d.ts +1 -0
- package/dist/{types/PromiseReturnType.js → utils/packageVersion.js} +2 -0
- package/package.json +26 -21
- package/yarn.lock +165 -237
- package/dist/entrypoint.api.d.ts +0 -22
- package/dist/entrypoint.api.js +0 -57
- package/dist/entrypoint.api.private.test.js +0 -37
- package/dist/index.d.ts +0 -783
- package/dist/index.js +0 -8001
- package/dist/ink.d.ts +0 -1
- package/dist/ink.js +0 -49
- package/dist/main.d.ts +0 -14
- package/dist/main.js +0 -68
- package/dist/options/config/getOptionsFromGit.d.ts +0 -4
- package/dist/options/config/getOptionsFromGit.js +0 -8
- package/dist/options/config/getProjectConfig.d.ts +0 -0
- package/dist/options/config/getProjectConfig.js +0 -1
- package/dist/options/getValidatedOptions.d.ts +0 -49
- package/dist/options/getValidatedOptions.js +0 -45
- package/dist/options/getValidatedOptions.test.js +0 -97
- package/dist/options/parseRequiredOptions.d.ts +0 -71
- package/dist/options/parseRequiredOptions.js +0 -68
- package/dist/options/parseRequiredOptions.test.js +0 -122
- package/dist/react-components/0-loadOptions.d.ts +0 -6
- package/dist/react-components/1-loadCommit.d.ts +0 -8
- package/dist/react-components/1-loadCommit.js +0 -88
- package/dist/react-components/1a-loadCommit.d.ts +0 -5
- package/dist/react-components/1a-loadCommit.js +0 -76
- package/dist/react-components/1b-commitChoices.d.ts +0 -5
- package/dist/react-components/1b-commitChoices.js +0 -98
- package/dist/react-components/2-commitChoices.d.ts +0 -8
- package/dist/react-components/2-commitChoices.js +0 -96
- package/dist/react-components/2-commitsPrompt.d.ts +0 -8
- package/dist/react-components/2-commitsPrompt.js +0 -96
- package/dist/react-components/2-targetBranchChoices.d.ts +0 -9
- package/dist/react-components/2-targetBranchChoices.js +0 -109
- package/dist/react-components/3-cherrypick.d.ts +0 -1
- package/dist/react-components/3-cherrypick.js +0 -2
- package/dist/react-components/App.d.ts +0 -2
- package/dist/react-components/App.js +0 -35
- package/dist/react-components/BackportStateContext.d.ts +0 -33
- package/dist/react-components/BackportStateContext.js +0 -42
- package/dist/react-components/CommitPrompt/2-commitsPrompt.d.ts +0 -8
- package/dist/react-components/CommitPrompt/2-commitsPrompt.js +0 -96
- package/dist/react-components/CommitPrompt/CommitPrompt.d.ts +0 -8
- package/dist/react-components/CommitPrompt/CommitPrompt.js +0 -96
- package/dist/react-components/CommitPrompt/getCommits.d.ts +0 -2
- package/dist/react-components/CommitPrompt/getCommits.js +0 -27
- package/dist/react-components/CommitPrompt.d.ts +0 -8
- package/dist/react-components/CommitPrompt.js +0 -96
- package/dist/react-components/CustomMultiSelect.d.ts +0 -13
- package/dist/react-components/CustomMultiSelect.js +0 -21
- package/dist/react-components/CustomMultiSelectItem.d.ts +0 -5
- package/dist/react-components/CustomMultiSelectItem.js +0 -12
- package/dist/react-components/CustomSelect.d.ts +0 -14
- package/dist/react-components/CustomSelect.js +0 -34
- package/dist/react-components/ErrorBoundary.d.ts +0 -15
- package/dist/react-components/ErrorBoundary.js +0 -53
- package/dist/react-components/MultiSelect.d.ts +0 -7
- package/dist/react-components/MultiSelect.js +0 -16
- package/dist/react-components/hooks/useAsync.d.ts +0 -12
- package/dist/react-components/hooks/useAsync.js +0 -73
- package/dist/runWithOptions.d.ts +0 -9
- package/dist/runWithOptions.js +0 -43
- package/dist/runWithOptions.test.js +0 -304
- package/dist/scripts/generate-gql.d.ts +0 -1
- package/dist/scripts/generate-gql.js +0 -15
- package/dist/services/backportRun/backportRun.ci.d.ts +0 -6
- package/dist/services/backportRun/backportRun.ci.js +0 -81
- package/dist/services/backportRun/backportRun.d.ts +0 -14
- package/dist/services/backportRun/backportRun.interactive.d.ts +0 -1
- package/dist/services/backportRun/backportRun.interactive.js +0 -4
- package/dist/services/backportRun/backportRun.js +0 -14
- package/dist/services/backportRun/backportState.d.ts +0 -4
- package/dist/services/backportRun/backportState.js +0 -28
- package/dist/services/backportRun/getCommits.d.ts +0 -2
- package/dist/services/backportRun/getCommits.js +0 -20
- package/dist/services/backportRun/runSequentially.d.ts +0 -20
- package/dist/services/backportRun/runSequentially.js +0 -41
- package/dist/services/backportRun/runSequentially.test.d.ts +0 -1
- package/dist/services/backportRun/runSequentially.test.js +0 -199
- package/dist/services/cherrypickAndCreateTargetPullRequest.d.ts +0 -12
- package/dist/services/cherrypickAndCreateTargetPullRequest.js +0 -206
- package/dist/services/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
- package/dist/services/cherrypickAndCreateTargetPullRequest.test.js +0 -403
- package/dist/services/fs-promisified.d.ts +0 -6
- package/dist/services/fs-promisified.js +0 -12
- package/dist/services/getCommits.d.ts +0 -2
- package/dist/services/getCommits.js +0 -38
- package/dist/services/getCommitsWithoutBackports.d.ts +0 -11
- package/dist/services/getCommitsWithoutBackports.js +0 -68
- package/dist/services/getCommitsWithoutBackports.test.d.ts +0 -1
- package/dist/services/getCommitsWithoutBackports.test.js +0 -259
- package/dist/services/getExpectedTarget.d.ts +0 -9
- package/dist/services/getExpectedTarget.js +0 -77
- package/dist/services/getExpectedTargetPullRequests.d.ts +0 -9
- package/dist/services/getExpectedTargetPullRequests.js +0 -77
- package/dist/services/getTargetBranches.d.ts +0 -5
- package/dist/services/getTargetBranches.js +0 -60
- package/dist/services/getTargetBranches.test.d.ts +0 -1
- package/dist/services/getTargetBranches.test.js +0 -180
- package/dist/services/github/v4/fetchCommitByPullNumber.d.ts +0 -5
- package/dist/services/github/v4/fetchCommitByPullNumber.js +0 -86
- package/dist/services/github/v4/fetchCommitByPullNumber.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +0 -57
- package/dist/services/github/v4/fetchCommitBySha.d.ts +0 -5
- package/dist/services/github/v4/fetchCommitBySha.js +0 -95
- package/dist/services/github/v4/fetchCommitBySha.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommitBySha.private.test.js +0 -50
- package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +0 -28
- package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +0 -52
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +0 -3
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +0 -55
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +0 -252
- package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +0 -28
- package/dist/services/github/v4/fetchCommitsByAuthor.js +0 -161
- package/dist/services/github/v4/fetchCommitsByAuthor.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +0 -115
- package/dist/services/github/v4/fetchCommitsByAuthor.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommitsByAuthor.test.js +0 -272
- package/dist/services/github/v4/fetchDefaultBranch.d.ts +0 -9
- package/dist/services/github/v4/fetchDefaultBranch.js +0 -24
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +0 -4
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +0 -52
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +0 -32
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +0 -4
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +0 -72
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +0 -34
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +0 -40
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +0 -72
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +0 -17
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks.js +0 -69
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +0 -32
- package/dist/services/github/v4/fetchMergedPullRequests.d.ts +0 -37
- package/dist/services/github/v4/fetchMergedPullRequests.js +0 -37
- package/dist/services/github/v4/fetchMergedPullRequests.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +0 -59
- package/dist/services/github/v4/fetchMergedPullRequests.test.d.ts +0 -1
- package/dist/services/github/v4/fetchMergedPullRequests.test.js +0 -22
- package/dist/services/github/v4/fetchProjectConfig.d.ts +0 -8
- package/dist/services/github/v4/fetchProjectConfig.js +0 -56
- package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +0 -52
- package/dist/services/github/v4/fetchProjectConfig.test.d.ts +0 -1
- package/dist/services/github/v4/fetchProjectConfig.test.js +0 -37
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.d.ts +0 -9
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +0 -92
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +0 -66
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.d.ts +0 -1
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +0 -242
- package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +0 -7
- package/dist/services/github/v4/getExistingTargetPullRequests.js +0 -45
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +0 -63
- package/dist/services/github/v4/getOptionsFromGithub/index.js +0 -139
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +0 -1
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +0 -147
- package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -5
- package/dist/services/github/v4/getTargetBranchesFromLabels.js +0 -20
- package/dist/services/github/v4/getTargetBranchesFromLabels.test.d.ts +0 -1
- package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +0 -201
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +0 -2
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +0 -843
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +0 -2
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +0 -73
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +0 -12
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +0 -44
- package/dist/services/maybeSetupRepo.d.ts +0 -2
- package/dist/services/maybeSetupRepo.js +0 -33
- package/dist/services/maybeSetupRepo.test.d.ts +0 -1
- package/dist/services/maybeSetupRepo.test.js +0 -78
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +0 -5
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +0 -20
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +0 -1
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +0 -201
- package/dist/services/sourceCommit/sourceCommit.d.ts +0 -78
- package/dist/services/sourceCommit/sourceCommit.js +0 -86
- package/dist/services/sourceCommit/sourceCommit.test.d.ts +0 -1
- package/dist/services/sourceCommit/sourceCommit.test.js +0 -287
- package/dist/services/sourceCommit.d.ts +0 -78
- package/dist/services/sourceCommit.js +0 -86
- package/dist/services/sourceCommit.test.d.ts +0 -1
- package/dist/services/sourceCommit.test.js +0 -280
- package/dist/test/backport-e2e.private.test.d.ts +0 -1
- package/dist/test/inquirer.private.test.d.ts +0 -1
- package/dist/test/inquirer.private.test.js +0 -168
- package/dist/test/integration/createSpies.d.ts +0 -17
- package/dist/test/integration/createSpies.js +0 -85
- package/dist/test/integration/envConstants.d.ts +0 -5
- package/dist/test/integration/envConstants.js +0 -9
- package/dist/test/integration/helpers.d.ts +0 -7
- package/dist/test/integration/helpers.js +0 -31
- package/dist/test/integration/integration.private.test.d.ts +0 -1
- package/dist/test/integration/integration.private.test.js +0 -327
- package/dist/test/integration/integration.test.d.ts +0 -1
- package/dist/test/integration/integration.test.js +0 -214
- package/dist/todo-delete.d.ts +0 -1
- package/dist/todo-delete.js +0 -17
- package/dist/types/Commit.d.ts +0 -85
- package/dist/types/Commit.js +0 -139
- package/dist/types/PromiseReturnType.d.ts +0 -1
- package/dist/types/commitNode.d.ts +0 -89
- package/dist/types/commitNode.js +0 -139
- package/dist/types/commitNode.test.d.ts +0 -1
- package/dist/types/commitNode.test.js +0 -255
- package/dist/types/commitWithAssociatedPullRequests.d.ts +0 -86
- package/dist/types/commitWithAssociatedPullRequests.js +0 -145
- package/dist/ui/cherrypickAndCreatePullRequest.test.d.ts +0 -1
- package/dist/ui/cherrypickAndCreatePullRequest.test.js +0 -617
- package/dist/ui/getTargetBranchesFromLabels.d.ts +0 -6
- package/dist/ui/getTargetBranchesFromLabels.js +0 -40
- package/dist/ui/getTargetBranchesFromLabels.test.d.ts +0 -1
- package/dist/ui/getTargetBranchesFromLabels.test.js +0 -288
- package/dist/utils/sequentially.d.ts +0 -1
- package/dist/utils/sequentially.js +0 -10
|
@@ -9,6 +9,10 @@ const logger_1 = require("../../../logger");
|
|
|
9
9
|
const apiRequestV4_1 = require("../apiRequestV4");
|
|
10
10
|
const throwOnInvalidAccessToken_1 = require("../throwOnInvalidAccessToken");
|
|
11
11
|
const query_1 = require("./query");
|
|
12
|
+
// fetches the default source branch for the repo (normally "master")
|
|
13
|
+
// startup checks:
|
|
14
|
+
// - verify the access token
|
|
15
|
+
// - ensure no branch named "backport" exists
|
|
12
16
|
async function getOptionsFromGithub(options) {
|
|
13
17
|
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
|
|
14
18
|
let res;
|
|
@@ -18,38 +22,37 @@ async function getOptionsFromGithub(options) {
|
|
|
18
22
|
accessToken,
|
|
19
23
|
query: query_1.query,
|
|
20
24
|
variables: { repoOwner, repoName },
|
|
21
|
-
handleError: false,
|
|
22
25
|
});
|
|
23
26
|
}
|
|
24
27
|
catch (e) {
|
|
28
|
+
if (!(e instanceof apiRequestV4_1.GithubV4Exception)) {
|
|
29
|
+
throw e;
|
|
30
|
+
}
|
|
25
31
|
const error = e;
|
|
26
|
-
(0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
|
|
27
|
-
|
|
28
|
-
repoName,
|
|
29
|
-
repoOwner,
|
|
30
|
-
});
|
|
31
|
-
res = handleMissingConfigFile(error);
|
|
32
|
+
(0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({ error, repoName, repoOwner });
|
|
33
|
+
res = swallowErrorIfConfigFileIsMissing(error);
|
|
32
34
|
}
|
|
33
|
-
// get the original repo (not the fork)
|
|
34
|
-
const repo = res.repository.isFork ? res.repository.parent : res.repository;
|
|
35
35
|
// it is not possible to have a branch named "backport"
|
|
36
|
-
if (
|
|
36
|
+
if (res.repository.illegalBackportBranch) {
|
|
37
37
|
throw new HandledError_1.HandledError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
|
|
38
38
|
}
|
|
39
|
-
const historicalRemoteConfigs =
|
|
39
|
+
const historicalRemoteConfigs = res.repository.defaultBranchRef.target.history.edges;
|
|
40
40
|
const latestRemoteConfig = historicalRemoteConfigs[0]?.remoteConfig;
|
|
41
|
-
const skipRemoteConfig = await getSkipRemoteConfigFile(options.skipRemoteConfig, latestRemoteConfig);
|
|
41
|
+
const skipRemoteConfig = await getSkipRemoteConfigFile(options.cwd, options.skipRemoteConfig, latestRemoteConfig);
|
|
42
|
+
const remoteConfig = skipRemoteConfig
|
|
43
|
+
? {}
|
|
44
|
+
: parseRemoteConfig(latestRemoteConfig);
|
|
42
45
|
return {
|
|
43
46
|
authenticatedUsername: res.viewer.login,
|
|
44
|
-
sourceBranch:
|
|
45
|
-
...
|
|
47
|
+
sourceBranch: res.repository.defaultBranchRef.name,
|
|
48
|
+
...remoteConfig,
|
|
46
49
|
historicalBranchLabelMappings: skipRemoteConfig
|
|
47
50
|
? []
|
|
48
51
|
: getHistoricalBranchLabelMappings(historicalRemoteConfigs),
|
|
49
52
|
};
|
|
50
53
|
}
|
|
51
54
|
exports.getOptionsFromGithub = getOptionsFromGithub;
|
|
52
|
-
async function getSkipRemoteConfigFile(skipRemoteConfig, remoteConfig) {
|
|
55
|
+
async function getSkipRemoteConfigFile(cwd, skipRemoteConfig, remoteConfig) {
|
|
53
56
|
if (skipRemoteConfig) {
|
|
54
57
|
logger_1.logger.info('Skipping remote config: `--skip-remote-config` specified via config file or cli');
|
|
55
58
|
return true;
|
|
@@ -58,23 +61,25 @@ async function getSkipRemoteConfigFile(skipRemoteConfig, remoteConfig) {
|
|
|
58
61
|
logger_1.logger.info("Skipping remote config: remote config doesn't exist");
|
|
59
62
|
return true;
|
|
60
63
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
64
|
+
if (cwd) {
|
|
65
|
+
const [isLocalConfigModified, isLocalConfigUntracked, localCommitDate] = await Promise.all([
|
|
66
|
+
(0, git_1.isLocalConfigFileModified)({ cwd }),
|
|
67
|
+
(0, git_1.isLocalConfigFileUntracked)({ cwd }),
|
|
68
|
+
(0, git_1.getLocalConfigFileCommitDate)({ cwd }),
|
|
69
|
+
]);
|
|
70
|
+
if (isLocalConfigUntracked) {
|
|
71
|
+
logger_1.logger.info('Skipping remote config: local config is new');
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
if (isLocalConfigModified) {
|
|
75
|
+
logger_1.logger.info('Skipping remote config: local config is modified');
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
if (localCommitDate &&
|
|
79
|
+
localCommitDate > Date.parse(remoteConfig.committedDate)) {
|
|
80
|
+
logger_1.logger.info(`Skipping remote config: local config is newer: ${new Date(localCommitDate).toISOString()} > ${remoteConfig.committedDate}`);
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
78
83
|
}
|
|
79
84
|
return false;
|
|
80
85
|
}
|
|
@@ -111,13 +116,16 @@ function getHistoricalBranchLabelMappings(historicalRemoteConfigs) {
|
|
|
111
116
|
})
|
|
112
117
|
.filter(filterEmpty_1.filterNil);
|
|
113
118
|
}
|
|
114
|
-
function
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
function swallowErrorIfConfigFileIsMissing(error) {
|
|
120
|
+
const { data, errors } = error.axiosResponse.data;
|
|
121
|
+
const wasMissingConfigError = errors?.some((error) => {
|
|
122
|
+
const isMatch = /^repository.defaultBranchRef.target.history.edges.\d+.remoteConfig.file$/.test(error.path.join('.'));
|
|
123
|
+
return isMatch && error.type === 'NOT_FOUND';
|
|
124
|
+
});
|
|
125
|
+
// swallow error if it's just the config file that's missing
|
|
126
|
+
if (wasMissingConfigError && data != null) {
|
|
127
|
+
return data;
|
|
121
128
|
}
|
|
122
|
-
|
|
129
|
+
// Throw unexpected error
|
|
130
|
+
throw error;
|
|
123
131
|
}
|
|
@@ -20,6 +20,7 @@ describe('getOptionsFromGithub', () => {
|
|
|
20
20
|
accessToken: 'foo',
|
|
21
21
|
repoOwner: 'backport-org',
|
|
22
22
|
repoName: 'backport-e2e',
|
|
23
|
+
cwd: process.cwd(),
|
|
23
24
|
};
|
|
24
25
|
await expect((0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions)).rejects.toThrowError('Please check your access token and make sure it is valid.\nConfig: /myHomeDir/.backport/config.json');
|
|
25
26
|
});
|
|
@@ -31,6 +32,7 @@ describe('getOptionsFromGithub', () => {
|
|
|
31
32
|
accessToken: devAccessToken,
|
|
32
33
|
repoOwner: 'backport-org',
|
|
33
34
|
repoName: 'backport-e2e',
|
|
35
|
+
cwd: process.cwd(),
|
|
34
36
|
};
|
|
35
37
|
expect(await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions)).toEqual({
|
|
36
38
|
authenticatedUsername: 'sqren',
|
|
@@ -77,6 +79,7 @@ describe('getOptionsFromGithub', () => {
|
|
|
77
79
|
accessToken: devAccessToken,
|
|
78
80
|
repoOwner: 'sqren',
|
|
79
81
|
repoName: 'backport-e2e',
|
|
82
|
+
cwd: process.cwd(),
|
|
80
83
|
};
|
|
81
84
|
const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
82
85
|
await expect(options.repoOwner).toEqual('backport-org');
|
|
@@ -90,6 +93,7 @@ describe('getOptionsFromGithub', () => {
|
|
|
90
93
|
accessToken: devAccessToken,
|
|
91
94
|
repoOwner: 'backport-org',
|
|
92
95
|
repoName: 'repo-with-non-standard-main-branch',
|
|
96
|
+
cwd: process.cwd(),
|
|
93
97
|
};
|
|
94
98
|
const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
95
99
|
await expect(options.sourceBranch).toEqual('my-custom-default-branch');
|
|
@@ -104,6 +108,7 @@ describe('getOptionsFromGithub', () => {
|
|
|
104
108
|
accessToken: devAccessToken,
|
|
105
109
|
repoOwner: 'backport-org',
|
|
106
110
|
repoName: 'repo-with-branch-named-backport',
|
|
111
|
+
cwd: process.cwd(),
|
|
107
112
|
};
|
|
108
113
|
await expect(async () => {
|
|
109
114
|
await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
@@ -118,6 +123,7 @@ describe('getOptionsFromGithub', () => {
|
|
|
118
123
|
accessToken: devAccessToken,
|
|
119
124
|
repoOwner: 'backport-org',
|
|
120
125
|
repoName: 'repo-with-backportrc-removed',
|
|
126
|
+
cwd: process.cwd(),
|
|
121
127
|
};
|
|
122
128
|
const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
123
129
|
expect(options).toEqual({
|
|
@@ -6,32 +6,24 @@ export declare type RemoteConfig = {
|
|
|
6
6
|
};
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
-
export declare type Repository = {
|
|
10
|
-
ref: {
|
|
11
|
-
name: string;
|
|
12
|
-
} | null;
|
|
13
|
-
defaultBranchRef: {
|
|
14
|
-
name: string;
|
|
15
|
-
target: {
|
|
16
|
-
history: {
|
|
17
|
-
edges: Array<{
|
|
18
|
-
remoteConfig: RemoteConfig;
|
|
19
|
-
}>;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
9
|
export interface GithubConfigOptionsResponse {
|
|
25
10
|
viewer: {
|
|
26
11
|
login: string;
|
|
27
12
|
};
|
|
28
13
|
repository: {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
14
|
+
illegalBackportBranch: {
|
|
15
|
+
id: string;
|
|
16
|
+
} | null;
|
|
17
|
+
defaultBranchRef: {
|
|
18
|
+
name: string;
|
|
19
|
+
target: {
|
|
20
|
+
history: {
|
|
21
|
+
edges: Array<{
|
|
22
|
+
remoteConfig: RemoteConfig;
|
|
23
|
+
}>;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
36
28
|
}
|
|
37
|
-
export declare const query = "\n query GithubConfigOptions($repoOwner: String!, $repoName: String!) {\n viewer {\n login\n }\n repository(owner: $repoOwner, name: $repoName) {\n
|
|
29
|
+
export declare const query = "\n query GithubConfigOptions($repoOwner: String!, $repoName: String!) {\n viewer {\n login\n }\n repository(owner: $repoOwner, name: $repoName) {\n # check to see if a branch named \"backport\" exists\n illegalBackportBranch: ref(qualifiedName: \"refs/heads/backport\") {\n id\n }\n defaultBranchRef {\n name\n target {\n ... on Commit {\n history(first: 20, path: \".backportrc.json\") {\n edges {\n remoteConfig: node {\n committedDate\n file(path: \".backportrc.json\") {\n ... on TreeEntry {\n object {\n ... on Blob {\n text\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n";
|
|
@@ -7,32 +7,24 @@ exports.query = `
|
|
|
7
7
|
login
|
|
8
8
|
}
|
|
9
9
|
repository(owner: $repoOwner, name: $repoName) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
...Repo
|
|
10
|
+
# check to see if a branch named "backport" exists
|
|
11
|
+
illegalBackportBranch: ref(qualifiedName: "refs/heads/backport") {
|
|
12
|
+
id
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
remoteConfig: node {
|
|
30
|
-
committedDate
|
|
31
|
-
file(path: ".backportrc.json") {
|
|
32
|
-
... on TreeEntry {
|
|
33
|
-
object {
|
|
34
|
-
... on Blob {
|
|
35
|
-
text
|
|
14
|
+
defaultBranchRef {
|
|
15
|
+
name
|
|
16
|
+
target {
|
|
17
|
+
... on Commit {
|
|
18
|
+
history(first: 20, path: ".backportrc.json") {
|
|
19
|
+
edges {
|
|
20
|
+
remoteConfig: node {
|
|
21
|
+
committedDate
|
|
22
|
+
file(path: ".backportrc.json") {
|
|
23
|
+
... on TreeEntry {
|
|
24
|
+
object {
|
|
25
|
+
... on Blob {
|
|
26
|
+
text
|
|
27
|
+
}
|
|
36
28
|
}
|
|
37
29
|
}
|
|
38
30
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare function getRepoOwnerAndNameFromGitRemotes({ accessToken, githubApiBaseUrlV4, cwd, }: {
|
|
2
|
+
accessToken: string;
|
|
3
|
+
githubApiBaseUrlV4?: string;
|
|
4
|
+
cwd: string;
|
|
5
|
+
}): Promise<{
|
|
6
|
+
repoOwner?: string;
|
|
7
|
+
repoName?: string;
|
|
8
|
+
}>;
|
|
9
|
+
export interface RepoOwnerAndNameResponse {
|
|
10
|
+
repository: {
|
|
11
|
+
isFork: true;
|
|
12
|
+
name: string;
|
|
13
|
+
owner: {
|
|
14
|
+
login: string;
|
|
15
|
+
};
|
|
16
|
+
parent: {
|
|
17
|
+
owner: {
|
|
18
|
+
login: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
} | {
|
|
22
|
+
isFork: false;
|
|
23
|
+
name: string;
|
|
24
|
+
owner: {
|
|
25
|
+
login: string;
|
|
26
|
+
};
|
|
27
|
+
parent: null;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRepoOwnerAndNameFromGitRemotes = void 0;
|
|
4
|
+
const maybe_1 = require("../../../utils/maybe");
|
|
5
|
+
const git_1 = require("../../git");
|
|
6
|
+
const logger_1 = require("../../logger");
|
|
7
|
+
const apiRequestV4_1 = require("./apiRequestV4");
|
|
8
|
+
async function getRepoOwnerAndNameFromGitRemotes({ accessToken, githubApiBaseUrlV4, cwd, }) {
|
|
9
|
+
const remotes = await (0, git_1.getRepoInfoFromGitRemotes)({ cwd });
|
|
10
|
+
const firstRemote = (0, maybe_1.maybe)(remotes[0]);
|
|
11
|
+
if (!firstRemote) {
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
16
|
+
githubApiBaseUrlV4,
|
|
17
|
+
accessToken,
|
|
18
|
+
query,
|
|
19
|
+
variables: {
|
|
20
|
+
repoOwner: firstRemote.repoOwner,
|
|
21
|
+
repoName: firstRemote.repoName,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
repoName: res.repository.name,
|
|
26
|
+
// get the original owner (not the fork owner)
|
|
27
|
+
repoOwner: res.repository.isFork
|
|
28
|
+
? res.repository.parent.owner.login
|
|
29
|
+
: res.repository.owner.login,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
if (e instanceof apiRequestV4_1.GithubV4Exception) {
|
|
34
|
+
logger_1.logger.error(e.message);
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
throw e;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.getRepoOwnerAndNameFromGitRemotes = getRepoOwnerAndNameFromGitRemotes;
|
|
41
|
+
const query = /* GraphQL */ `
|
|
42
|
+
query RepoOwnerAndName($repoOwner: String!, $repoName: String!) {
|
|
43
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
44
|
+
isFork
|
|
45
|
+
name
|
|
46
|
+
owner {
|
|
47
|
+
login
|
|
48
|
+
}
|
|
49
|
+
parent {
|
|
50
|
+
owner {
|
|
51
|
+
login
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
File without changes
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
23
|
+
const sandbox_1 = require("../../../test/sandbox");
|
|
24
|
+
const childProcess = __importStar(require("../../child-process-promisified"));
|
|
25
|
+
const getRepoOwnerAndNameFromGitRemotes_1 = require("./getRepoOwnerAndNameFromGitRemotes");
|
|
26
|
+
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
27
|
+
describe('fetchRemoteProjectConfig', () => {
|
|
28
|
+
let devAccessToken;
|
|
29
|
+
beforeEach(async () => {
|
|
30
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
31
|
+
});
|
|
32
|
+
describe('when the remote is a fork', () => {
|
|
33
|
+
it('retrives the original owner from github', async () => {
|
|
34
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
35
|
+
const execOpts = { cwd: sandboxPath };
|
|
36
|
+
await childProcess.exec(`git init`, execOpts);
|
|
37
|
+
await childProcess.exec(`git remote add sqren git@github.com:sqren/kibana.git`, execOpts);
|
|
38
|
+
expect(await (0, getRepoOwnerAndNameFromGitRemotes_1.getRepoOwnerAndNameFromGitRemotes)({
|
|
39
|
+
accessToken: devAccessToken,
|
|
40
|
+
cwd: sandboxPath,
|
|
41
|
+
})).toEqual({
|
|
42
|
+
repoName: 'kibana',
|
|
43
|
+
repoOwner: 'elastic',
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe('when none of the git remotes are found', () => {
|
|
48
|
+
it('swallows the error and returns empty', async () => {
|
|
49
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
50
|
+
const execOpts = { cwd: sandboxPath };
|
|
51
|
+
await childProcess.exec(`git init`, execOpts);
|
|
52
|
+
await childProcess.exec(`git remote add foo git@github.com:foo/kibana.git`, execOpts);
|
|
53
|
+
await childProcess.exec(`git remote add bar git@github.com:bar/kibana.git`, execOpts);
|
|
54
|
+
expect(await (0, getRepoOwnerAndNameFromGitRemotes_1.getRepoOwnerAndNameFromGitRemotes)({
|
|
55
|
+
accessToken: devAccessToken,
|
|
56
|
+
cwd: sandboxPath,
|
|
57
|
+
})).toEqual({});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe('when there are no git remotes', () => {
|
|
61
|
+
it('returns empty', async () => {
|
|
62
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
63
|
+
const execOpts = { cwd: sandboxPath };
|
|
64
|
+
await childProcess.exec(`git init`, execOpts);
|
|
65
|
+
expect(await (0, getRepoOwnerAndNameFromGitRemotes_1.getRepoOwnerAndNameFromGitRemotes)({
|
|
66
|
+
accessToken: devAccessToken,
|
|
67
|
+
cwd: sandboxPath,
|
|
68
|
+
})).toEqual({});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -14,7 +14,7 @@ exports.commitsByAuthorMock = {
|
|
|
14
14
|
owner: { login: 'elastic' },
|
|
15
15
|
},
|
|
16
16
|
committedDate: '2021-12-24T00:00:00Z',
|
|
17
|
-
|
|
17
|
+
sha: '2e63475c483f7844b0f2833bc57fdee32095bacb',
|
|
18
18
|
message: 'Add 👻',
|
|
19
19
|
associatedPullRequests: {
|
|
20
20
|
edges: [],
|
|
@@ -28,7 +28,7 @@ exports.commitsByAuthorMock = {
|
|
|
28
28
|
owner: { login: 'elastic' },
|
|
29
29
|
},
|
|
30
30
|
committedDate: '2021-12-23T00:00:00Z',
|
|
31
|
-
|
|
31
|
+
sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
|
|
32
32
|
message: 'Add witch (#85)',
|
|
33
33
|
associatedPullRequests: {
|
|
34
34
|
edges: [
|
|
@@ -40,8 +40,8 @@ exports.commitsByAuthorMock = {
|
|
|
40
40
|
nodes: [{ name: 'my-label-b' }],
|
|
41
41
|
},
|
|
42
42
|
number: 85,
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
mergeCommit: {
|
|
44
|
+
sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
|
|
45
45
|
message: 'Add witch (#85)',
|
|
46
46
|
},
|
|
47
47
|
timelineItems: {
|
|
@@ -60,7 +60,7 @@ exports.commitsByAuthorMock = {
|
|
|
60
60
|
owner: { login: 'elastic' },
|
|
61
61
|
},
|
|
62
62
|
committedDate: '2021-12-22T00:00:00Z',
|
|
63
|
-
|
|
63
|
+
sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
|
|
64
64
|
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
65
65
|
associatedPullRequests: {
|
|
66
66
|
edges: [
|
|
@@ -72,8 +72,8 @@ exports.commitsByAuthorMock = {
|
|
|
72
72
|
},
|
|
73
73
|
baseRefName: 'master',
|
|
74
74
|
number: 80,
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
mergeCommit: {
|
|
76
|
+
sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
|
|
77
77
|
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
78
78
|
},
|
|
79
79
|
timelineItems: {
|
|
@@ -83,7 +83,7 @@ exports.commitsByAuthorMock = {
|
|
|
83
83
|
targetPullRequest: {
|
|
84
84
|
__typename: 'PullRequest',
|
|
85
85
|
targetMergeCommit: {
|
|
86
|
-
|
|
86
|
+
sha: 'target-merge-commit-sha',
|
|
87
87
|
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
88
88
|
},
|
|
89
89
|
repository: {
|
|
@@ -100,7 +100,7 @@ exports.commitsByAuthorMock = {
|
|
|
100
100
|
{
|
|
101
101
|
node: {
|
|
102
102
|
targetCommit: {
|
|
103
|
-
|
|
103
|
+
sha: 'abc',
|
|
104
104
|
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
105
105
|
},
|
|
106
106
|
},
|
|
@@ -125,7 +125,7 @@ exports.commitsByAuthorMock = {
|
|
|
125
125
|
owner: { login: 'elastic' },
|
|
126
126
|
},
|
|
127
127
|
committedDate: '2021-12-21T00:00:00Z',
|
|
128
|
-
|
|
128
|
+
sha: '3827bbbaf39914eda4f02f6940189844375fd097',
|
|
129
129
|
message: 'Add backport config',
|
|
130
130
|
associatedPullRequests: {
|
|
131
131
|
edges: [],
|
|
@@ -139,7 +139,7 @@ exports.commitsByAuthorMock = {
|
|
|
139
139
|
owner: { login: 'elastic' },
|
|
140
140
|
},
|
|
141
141
|
committedDate: '2021-12-20T00:00:00Z',
|
|
142
|
-
|
|
142
|
+
sha: '5ea0da550ac191029459289d67f99ad7d310812b',
|
|
143
143
|
message: 'Initial commit',
|
|
144
144
|
associatedPullRequests: {
|
|
145
145
|
edges: [],
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { GithubV4Exception } from './apiRequestV4';
|
|
2
|
+
export declare function throwOnInvalidAccessToken({ error, repoOwner, repoName, }: {
|
|
3
|
+
error: GithubV4Exception<unknown>;
|
|
4
4
|
repoOwner: string;
|
|
5
5
|
repoName: string;
|
|
6
|
-
|
|
7
|
-
}): void;
|
|
6
|
+
}): undefined;
|
|
@@ -2,22 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.throwOnInvalidAccessToken = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
|
+
const maybe_1 = require("../../../utils/maybe");
|
|
5
6
|
const HandledError_1 = require("../../HandledError");
|
|
6
7
|
const env_1 = require("../../env");
|
|
7
|
-
function throwOnInvalidAccessToken({ repoOwner, repoName,
|
|
8
|
+
function throwOnInvalidAccessToken({ error, repoOwner, repoName, }) {
|
|
8
9
|
function getSSOAuthUrl(ssoHeader) {
|
|
9
10
|
const matches = ssoHeader?.match(/url=(.*)/);
|
|
10
11
|
if (matches) {
|
|
11
12
|
return matches[1];
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
|
-
const statusCode = error.
|
|
15
|
+
const statusCode = error.axiosResponse.status;
|
|
15
16
|
switch (statusCode) {
|
|
16
17
|
case 200: {
|
|
17
|
-
const repoNotFound = error.
|
|
18
|
-
const grantedScopes = error.
|
|
19
|
-
const requiredScopes = error.
|
|
20
|
-
const ssoHeader = error.
|
|
18
|
+
const repoNotFound = error.axiosResponse.data.errors?.some((error) => error.type === 'NOT_FOUND' && error.path.join('.') === 'repository');
|
|
19
|
+
const grantedScopes = error.axiosResponse.headers['x-oauth-scopes'] || '';
|
|
20
|
+
const requiredScopes = error.axiosResponse.headers['x-accepted-oauth-scopes'] || '';
|
|
21
|
+
const ssoHeader = (0, maybe_1.maybe)(error.axiosResponse.headers['x-github-sso']);
|
|
21
22
|
if (repoNotFound) {
|
|
22
23
|
const hasRequiredScopes = (0, lodash_1.isEmpty)((0, lodash_1.difference)(requiredScopes.split(','), grantedScopes.split(',')));
|
|
23
24
|
// user does not have permission to the repo
|
|
@@ -27,7 +28,7 @@ function throwOnInvalidAccessToken({ repoOwner, repoName, error, }) {
|
|
|
27
28
|
// repo does not exist
|
|
28
29
|
throw new HandledError_1.HandledError(`The repository "${repoOwner}/${repoName}" doesn't exist`);
|
|
29
30
|
}
|
|
30
|
-
const repoAccessForbidden = error.
|
|
31
|
+
const repoAccessForbidden = error.axiosResponse.data.errors?.some((error) => error.type === 'FORBIDDEN');
|
|
31
32
|
const ssoAuthUrl = getSSOAuthUrl(ssoHeader);
|
|
32
33
|
// user does not have permissions
|
|
33
34
|
if (repoAccessForbidden && ssoAuthUrl) {
|
|
@@ -37,6 +38,8 @@ function throwOnInvalidAccessToken({ repoOwner, repoName, error, }) {
|
|
|
37
38
|
}
|
|
38
39
|
case 401:
|
|
39
40
|
throw new HandledError_1.HandledError(`Please check your access token and make sure it is valid.\nConfig: ${(0, env_1.getGlobalConfigPath)()}`);
|
|
41
|
+
default:
|
|
42
|
+
return undefined;
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
exports.throwOnInvalidAccessToken = throwOnInvalidAccessToken;
|
|
@@ -5,7 +5,7 @@ describe('throwOnInvalidAccessToken', () => {
|
|
|
5
5
|
describe('when status code is', () => {
|
|
6
6
|
it('should handle invalid access token', () => {
|
|
7
7
|
const error = {
|
|
8
|
-
|
|
8
|
+
axiosResponse: {
|
|
9
9
|
status: 401,
|
|
10
10
|
headers: {},
|
|
11
11
|
},
|
|
@@ -18,7 +18,7 @@ describe('throwOnInvalidAccessToken', () => {
|
|
|
18
18
|
});
|
|
19
19
|
it('should handle SSO error', () => {
|
|
20
20
|
const error = {
|
|
21
|
-
|
|
21
|
+
axiosResponse: {
|
|
22
22
|
status: 200,
|
|
23
23
|
headers: { 'x-github-sso': 'required; url=https://ssourl.com' },
|
|
24
24
|
data: {
|
|
@@ -34,7 +34,7 @@ describe('throwOnInvalidAccessToken', () => {
|
|
|
34
34
|
});
|
|
35
35
|
it('should handle non-existing repo', () => {
|
|
36
36
|
const error = {
|
|
37
|
-
|
|
37
|
+
axiosResponse: {
|
|
38
38
|
status: 200,
|
|
39
39
|
headers: {
|
|
40
40
|
'x-oauth-scopes': 'a,b,c',
|
|
@@ -53,7 +53,7 @@ describe('throwOnInvalidAccessToken', () => {
|
|
|
53
53
|
});
|
|
54
54
|
it('should handle insufficient permissions (oauth scopes)', () => {
|
|
55
55
|
const error = {
|
|
56
|
-
|
|
56
|
+
axiosResponse: {
|
|
57
57
|
status: 200,
|
|
58
58
|
headers: {
|
|
59
59
|
'x-oauth-scopes': 'a,b',
|
|
@@ -72,7 +72,7 @@ describe('throwOnInvalidAccessToken', () => {
|
|
|
72
72
|
});
|
|
73
73
|
it('should not handle unknown cases', () => {
|
|
74
74
|
const error = {
|
|
75
|
-
|
|
75
|
+
axiosResponse: {
|
|
76
76
|
status: 500,
|
|
77
77
|
headers: {},
|
|
78
78
|
},
|