backport 6.1.5 → 6.3.0-beta-2
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/{main.d.ts → backportRun.d.ts} +3 -3
- package/dist/{main.js → backportRun.js} +21 -10
- package/dist/{entrypoint.module.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/{options/getValidatedOptions.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 +5 -1
- package/dist/options/cliArgs.d.ts +16 -14
- package/dist/options/cliArgs.js +15 -5
- package/dist/options/cliArgs.test.js +28 -10
- package/dist/options/config/config.d.ts +10 -4
- 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 +19 -32
- 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 +27 -23
- package/dist/options/config/readConfigFile.js +2 -2
- package/dist/options/options.d.ts +18 -39
- package/dist/options/options.js +40 -32
- package/dist/options/options.test.js +83 -47
- package/dist/runSequentially.d.ts +0 -1
- package/dist/runSequentially.js +0 -1
- package/dist/runSequentially.test.js +39 -20
- 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 +165 -70
- package/dist/services/github/v3/getGithubV3ErrorMessage.d.ts +2 -1
- 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 +38 -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 +6 -2
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +41 -34
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +6 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +2 -1
- 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 +9 -3
- package/dist/services/logger.js +38 -35
- 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/{integration/integration.private.test.js → backport-e2e.mutation.test.js} +143 -123
- package/dist/{scripts/generate-gql.d.ts → test/handleUnbackportedPullRequests.private.test.d.ts} +0 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +57 -0
- 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/test/sandbox.js +43 -0
- 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 -14
- 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 +24 -20
- package/yarn.lock +160 -237
- 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/options/config/getOptionsFromGit.d.ts +0 -4
- package/dist/options/config/getOptionsFromGit.js +0 -8
- 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/runWithOptions.d.ts +0 -9
- package/dist/runWithOptions.js +0 -43
- package/dist/runWithOptions.test.js +0 -304
- package/dist/scripts/generate-gql.js +0 -15
- package/dist/services/fs-promisified.d.ts +0 -6
- package/dist/services/fs-promisified.js +0 -12
- 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/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/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/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.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
|
@@ -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,7 +6,7 @@ export declare type RemoteConfig = {
|
|
|
6
6
|
};
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
declare type Repository = {
|
|
10
10
|
ref: {
|
|
11
11
|
name: string;
|
|
12
12
|
} | null;
|
|
@@ -35,3 +35,4 @@ export interface GithubConfigOptionsResponse {
|
|
|
35
35
|
} & Repository);
|
|
36
36
|
}
|
|
37
37
|
export declare const query = "\n query GithubConfigOptions($repoOwner: String!, $repoName: String!) {\n viewer {\n login\n }\n repository(owner: $repoOwner, name: $repoName) {\n isFork\n ...Repo\n parent {\n ...Repo\n }\n }\n }\n\n fragment Repo on Repository {\n # check to see if a branch named \"backport\" exists\n ref(qualifiedName: \"refs/heads/backport\") {\n name\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";
|
|
38
|
+
export {};
|
|
@@ -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
|
},
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ConfigFileOptions } from '../options/ConfigOptions';
|
|
2
1
|
export declare function consoleLog(message: string): void;
|
|
3
2
|
export declare type Logger = typeof logger;
|
|
4
3
|
export declare const logger: {
|
|
@@ -8,8 +7,15 @@ export declare const logger: {
|
|
|
8
7
|
verbose: (message: string, meta?: unknown) => void;
|
|
9
8
|
debug: (message: string, meta?: unknown) => void;
|
|
10
9
|
};
|
|
11
|
-
export declare function updateLogger(
|
|
12
|
-
|
|
10
|
+
export declare function updateLogger({ accessToken, verbose, }: {
|
|
11
|
+
accessToken: string;
|
|
12
|
+
verbose?: boolean;
|
|
13
|
+
}): void;
|
|
14
|
+
export declare function initLogger({ ci, accessToken, logFilePath, }: {
|
|
15
|
+
ci?: boolean;
|
|
16
|
+
accessToken?: string;
|
|
17
|
+
logFilePath?: string;
|
|
18
|
+
}): {
|
|
13
19
|
error: (message: string, meta?: unknown) => void;
|
|
14
20
|
warn: (message: string, meta?: unknown) => void;
|
|
15
21
|
info: (message: string, meta?: unknown) => void;
|
package/dist/services/logger.js
CHANGED
|
@@ -55,50 +55,30 @@ exports.logger = {
|
|
|
55
55
|
winstonInstance.debug(message, null, { meta });
|
|
56
56
|
},
|
|
57
57
|
};
|
|
58
|
-
let
|
|
59
|
-
function updateLogger(
|
|
60
|
-
|
|
58
|
+
let _accessToken;
|
|
59
|
+
function updateLogger({ accessToken, verbose, }) {
|
|
60
|
+
// set access token
|
|
61
|
+
_accessToken = accessToken;
|
|
61
62
|
// set log level
|
|
62
|
-
winstonInstance.level =
|
|
63
|
-
// output logs to console in ci env
|
|
64
|
-
if (options.ci) {
|
|
65
|
-
winstonInstance.add(new winston_1.default.transports.Console());
|
|
66
|
-
}
|
|
63
|
+
winstonInstance.level = verbose ? 'debug' : 'info';
|
|
67
64
|
}
|
|
68
65
|
exports.updateLogger = updateLogger;
|
|
69
66
|
function redactAccessToken(str) {
|
|
70
67
|
// `redactAccessToken` might be called before access token is set
|
|
71
|
-
if (
|
|
72
|
-
return (0, redact_1.redact)(
|
|
68
|
+
if (_accessToken) {
|
|
69
|
+
return (0, redact_1.redact)(_accessToken, str);
|
|
73
70
|
}
|
|
74
71
|
return str;
|
|
75
72
|
}
|
|
76
|
-
function initLogger() {
|
|
73
|
+
function initLogger({ ci, accessToken, logFilePath, }) {
|
|
74
|
+
const fileTransport = getFileTransport({ logFilePath });
|
|
75
|
+
if (accessToken) {
|
|
76
|
+
_accessToken = accessToken;
|
|
77
|
+
}
|
|
77
78
|
winstonInstance = winston_1.default.createLogger({
|
|
78
|
-
transports:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
level: 'debug',
|
|
82
|
-
format: combine(winston_1.format.splat(), winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.default.format.metadata({
|
|
83
|
-
fillExcept: ['message', 'level', 'timestamp', 'label'],
|
|
84
|
-
}), winston_1.format.printf((info) => {
|
|
85
|
-
// format without metadata
|
|
86
|
-
if (!info.metadata.meta) {
|
|
87
|
-
return redactAccessToken(`${info.timestamp}: ${info.message}`);
|
|
88
|
-
}
|
|
89
|
-
// format when metadata is a string
|
|
90
|
-
if ((0, lodash_1.isString)(info.metadata.meta)) {
|
|
91
|
-
return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, dedent_1.default)(info.metadata.meta)}\n`);
|
|
92
|
-
}
|
|
93
|
-
if (info.metadata.meta.stack) {
|
|
94
|
-
return redactAccessToken(`${info.timestamp}: ${info.message}\n${info.metadata.meta.stack}\n`);
|
|
95
|
-
}
|
|
96
|
-
// format when metadata is an object
|
|
97
|
-
return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, safe_json_stringify_1.default)(info.metadata.meta, null, 2)}\n`);
|
|
98
|
-
})),
|
|
99
|
-
filename: (0, env_1.getLogfilePath)(),
|
|
100
|
-
}),
|
|
101
|
-
],
|
|
79
|
+
transports: ci
|
|
80
|
+
? [fileTransport, new winston_1.default.transports.Console()]
|
|
81
|
+
: [fileTransport],
|
|
102
82
|
});
|
|
103
83
|
// wait exiting until logs have been flushed to disk
|
|
104
84
|
winstonInstance.on('finish', () => {
|
|
@@ -107,6 +87,29 @@ function initLogger() {
|
|
|
107
87
|
return exports.logger;
|
|
108
88
|
}
|
|
109
89
|
exports.initLogger = initLogger;
|
|
90
|
+
function getFileTransport({ logFilePath }) {
|
|
91
|
+
return new winston_1.default.transports.File({
|
|
92
|
+
level: 'debug',
|
|
93
|
+
format: combine(winston_1.format.splat(), winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.default.format.metadata({
|
|
94
|
+
fillExcept: ['message', 'level', 'timestamp', 'label'],
|
|
95
|
+
}), winston_1.format.printf((info) => {
|
|
96
|
+
// format without metadata
|
|
97
|
+
if (!info.metadata.meta) {
|
|
98
|
+
return redactAccessToken(`${info.timestamp}: ${info.message}`);
|
|
99
|
+
}
|
|
100
|
+
// format when metadata is a string
|
|
101
|
+
if ((0, lodash_1.isString)(info.metadata.meta)) {
|
|
102
|
+
return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, dedent_1.default)(info.metadata.meta)}\n`);
|
|
103
|
+
}
|
|
104
|
+
if (info.metadata.meta.stack) {
|
|
105
|
+
return redactAccessToken(`${info.timestamp}: ${info.message}\n${info.metadata.meta.stack}\n`);
|
|
106
|
+
}
|
|
107
|
+
// format when metadata is an object
|
|
108
|
+
return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, safe_json_stringify_1.default)(info.metadata.meta, null, 2)}\n`);
|
|
109
|
+
})),
|
|
110
|
+
filename: (0, env_1.getLogfilePath)({ logFilePath }),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
110
113
|
// log levels:
|
|
111
114
|
// - error
|
|
112
115
|
// - warn
|
|
@@ -10,9 +10,20 @@ describe('prompt', () => {
|
|
|
10
10
|
it('should display status badges via `expectedTargetPullRequests`', () => {
|
|
11
11
|
const commits = [
|
|
12
12
|
{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
sourceBranch: 'master',
|
|
14
|
+
sourceCommit: {
|
|
15
|
+
committedDate: '1',
|
|
16
|
+
sha: 'ae9d51b7fe3ee6f30d0d196c782e0dcabb7ac5ff',
|
|
17
|
+
message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
|
|
18
|
+
},
|
|
19
|
+
sourcePullRequest: {
|
|
20
|
+
number: 119700,
|
|
21
|
+
url: 'foo',
|
|
22
|
+
mergeCommit: {
|
|
23
|
+
sha: 'ae9d51b7fe3ee6f30d0d196c782e0dcabb7ac5ff',
|
|
24
|
+
message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
16
27
|
expectedTargetPullRequests: [
|
|
17
28
|
{ number: 120178, branch: '8.0', state: 'MERGED' },
|
|
18
29
|
{ number: 120179, branch: '7.16', state: 'MERGED' },
|
|
@@ -31,35 +42,71 @@ describe('prompt', () => {
|
|
|
31
42
|
it('should list choices', () => {
|
|
32
43
|
const commits = [
|
|
33
44
|
{
|
|
34
|
-
committedDate: '',
|
|
35
45
|
sourceBranch: 'master',
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
sourceCommit: {
|
|
47
|
+
committedDate: '',
|
|
48
|
+
sha: 'b1b491959dab47aeb83c88ee2accb2db46d23793',
|
|
49
|
+
message: '[APM] Prefer service.name for logs correlation (#120694)',
|
|
50
|
+
},
|
|
51
|
+
sourcePullRequest: {
|
|
52
|
+
number: 120694,
|
|
53
|
+
url: 'foo',
|
|
54
|
+
mergeCommit: {
|
|
55
|
+
sha: 'b1b491959dab47aeb83c88ee2accb2db46d23793',
|
|
56
|
+
message: '[APM] Prefer service.name for logs correlation (#120694)',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
39
59
|
expectedTargetPullRequests: [],
|
|
40
60
|
},
|
|
41
61
|
{
|
|
42
|
-
committedDate: '',
|
|
43
62
|
sourceBranch: 'master',
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
63
|
+
sourceCommit: {
|
|
64
|
+
committedDate: '',
|
|
65
|
+
sha: 'b1bb4a93959f19a653b9cfb207a5c6acb6559482',
|
|
66
|
+
message: '[APM] Disable telemetry in agent config endpoint (#120106)',
|
|
67
|
+
},
|
|
68
|
+
sourcePullRequest: {
|
|
69
|
+
number: 120106,
|
|
70
|
+
url: 'foo',
|
|
71
|
+
mergeCommit: {
|
|
72
|
+
sha: 'b1bb4a93959f19a653b9cfb207a5c6acb6559482',
|
|
73
|
+
message: '[APM] Disable telemetry in agent config endpoint (#120106)',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
47
76
|
expectedTargetPullRequests: [],
|
|
48
77
|
},
|
|
49
78
|
{
|
|
50
|
-
committedDate: '',
|
|
51
79
|
sourceBranch: 'master',
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
80
|
+
sourceCommit: {
|
|
81
|
+
committedDate: '',
|
|
82
|
+
sha: '434f6e6a88faf24dc1ea41f9f726db78e46355a7',
|
|
83
|
+
message: '[APM] Remove index_pattern.json and add custom field formatters (#119915)',
|
|
84
|
+
},
|
|
85
|
+
sourcePullRequest: {
|
|
86
|
+
number: 119915,
|
|
87
|
+
url: 'foo',
|
|
88
|
+
mergeCommit: {
|
|
89
|
+
sha: '434f6e6a88faf24dc1ea41f9f726db78e46355a7',
|
|
90
|
+
message: '[APM] Remove index_pattern.json and add custom field formatters (#119915)',
|
|
91
|
+
},
|
|
92
|
+
},
|
|
55
93
|
expectedTargetPullRequests: [],
|
|
56
94
|
},
|
|
57
95
|
{
|
|
58
|
-
committedDate: '',
|
|
59
96
|
sourceBranch: 'master',
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
97
|
+
sourceCommit: {
|
|
98
|
+
committedDate: '',
|
|
99
|
+
sha: 'ae9d51b7fe3ee6f30d0d196c782e0dcabb7ac5ff',
|
|
100
|
+
message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
|
|
101
|
+
},
|
|
102
|
+
sourcePullRequest: {
|
|
103
|
+
number: 119700,
|
|
104
|
+
url: 'foo',
|
|
105
|
+
mergeCommit: {
|
|
106
|
+
sha: 'ae9d51b7fe3ee6f30d0d196c782e0dcabb7ac5ff',
|
|
107
|
+
message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
|
|
108
|
+
},
|
|
109
|
+
},
|
|
63
110
|
expectedTargetPullRequests: [],
|
|
64
111
|
},
|
|
65
112
|
];
|