@backstage/plugin-scaffolder-backend-module-github 0.0.0-nightly-20240513021609 → 0.0.0-nightly-20240518021458

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 CHANGED
@@ -1,16 +1,26 @@
1
1
  # @backstage/plugin-scaffolder-backend-module-github
2
2
 
3
- ## 0.0.0-nightly-20240513021609
3
+ ## 0.0.0-nightly-20240518021458
4
+
5
+ ### Patch Changes
6
+
7
+ - f145a04: Added handling for dry run to githubPullRequest and githubWebhook and added tests for this functionality
8
+ - Updated dependencies
9
+ - @backstage/backend-common@0.0.0-nightly-20240518021458
10
+ - @backstage/backend-plugin-api@0.0.0-nightly-20240518021458
11
+
12
+ ## 0.2.8
4
13
 
5
14
  ### Patch Changes
6
15
 
7
16
  - 5d99272: Update local development dependencies.
17
+ - d229dc4: Move path utilities from `backend-common` to the `backend-plugin-api` package.
8
18
  - 52ab241: Adding support to change the default commit author for `publish:github:pull-request`
9
19
  - Updated dependencies
10
- - @backstage/backend-common@0.0.0-nightly-20240513021609
11
- - @backstage/plugin-scaffolder-node@0.0.0-nightly-20240513021609
12
- - @backstage/integration@0.0.0-nightly-20240513021609
13
- - @backstage/backend-plugin-api@0.0.0-nightly-20240513021609
20
+ - @backstage/backend-common@0.22.0
21
+ - @backstage/backend-plugin-api@0.6.18
22
+ - @backstage/plugin-scaffolder-node@0.4.4
23
+ - @backstage/integration@1.11.0
14
24
 
15
25
  ## 0.2.8-next.2
16
26
 
package/dist/index.cjs.js CHANGED
@@ -10,7 +10,6 @@ var Sodium = require('libsodium-wrappers');
10
10
  var yaml = require('yaml');
11
11
  var webhooks = require('@octokit/webhooks');
12
12
  var path = require('path');
13
- var backendCommon = require('@backstage/backend-common');
14
13
  var octokitPluginCreatePullRequest = require('octokit-plugin-create-pull-request');
15
14
  var backendPluginApi = require('@backstage/backend-plugin-api');
16
15
  var alpha = require('@backstage/plugin-scaffolder-node/alpha');
@@ -58,7 +57,7 @@ const enableBranchProtectionOnDefaultRepoBranch = async ({
58
57
  strict: requireBranchesToBeUpToDate,
59
58
  contexts: requiredStatusCheckContexts
60
59
  },
61
- restrictions: restrictions != null ? restrictions : null,
60
+ restrictions: restrictions ?? null,
62
61
  enforce_admins: enforceAdmins,
63
62
  required_pull_request_reviews: {
64
63
  required_approving_review_count: requiredApprovingReviewCount,
@@ -104,7 +103,6 @@ function entityRefToName(name) {
104
103
 
105
104
  const DEFAULT_TIMEOUT_MS = 6e4;
106
105
  async function getOctokitOptions(options) {
107
- var _a;
108
106
  const { integrations, credentialsProvider, repoUrl, token } = options;
109
107
  const { owner, repo, host } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
110
108
  const requestOptions = {
@@ -114,7 +112,7 @@ async function getOctokitOptions(options) {
114
112
  if (!owner) {
115
113
  throw new errors.InputError(`No owner provided for repo ${repoUrl}`);
116
114
  }
117
- const integrationConfig = (_a = integrations.github.byHost(host)) == null ? void 0 : _a.config;
115
+ const integrationConfig = integrations.github.byHost(host)?.config;
118
116
  if (!integrationConfig) {
119
117
  throw new errors.InputError(`No integration for host ${host}`);
120
118
  }
@@ -126,7 +124,7 @@ async function getOctokitOptions(options) {
126
124
  request: requestOptions
127
125
  };
128
126
  }
129
- const githubCredentialsProvider = credentialsProvider != null ? credentialsProvider : integration.DefaultGithubCredentialsProvider.fromIntegrations(integrations);
127
+ const githubCredentialsProvider = credentialsProvider ?? integration.DefaultGithubCredentialsProvider.fromIntegrations(integrations);
130
128
  const { token: credentialProviderToken } = await githubCredentialsProvider.getCredentials({
131
129
  url: `https://${host}/${encodeURIComponent(owner)}/${encodeURIComponent(
132
130
  repo
@@ -147,7 +145,7 @@ async function createGithubRepoWithCollaboratorsAndTopics(client, repo, owner, r
147
145
  const user = await client.rest.users.getByUsername({
148
146
  username: owner
149
147
  });
150
- if (access == null ? void 0 : access.startsWith(`${owner}/`)) {
148
+ if (access?.startsWith(`${owner}/`)) {
151
149
  await validateAccessTeam(client, access);
152
150
  }
153
151
  const repoCreationPromise = user.data.type === "Organization" ? client.rest.repos.createInOrg({
@@ -198,7 +196,7 @@ async function createGithubRepoWithCollaboratorsAndTopics(client, repo, owner, r
198
196
  `Failed to create the ${user.data.type} repository ${owner}/${repo}, ${e.message}`
199
197
  );
200
198
  }
201
- if (access == null ? void 0 : access.startsWith(`${owner}/`)) {
199
+ if (access?.startsWith(`${owner}/`)) {
202
200
  const [, team] = access.split("/");
203
201
  await client.rest.teams.addOrUpdateRepoPermissionsInOrg({
204
202
  org: owner,
@@ -255,7 +253,7 @@ async function createGithubRepoWithCollaboratorsAndTopics(client, repo, owner, r
255
253
  logger.warn(`Skipping topics ${topics.join(" ")}, ${e.message}`);
256
254
  }
257
255
  }
258
- for (const [key, value] of Object.entries(repoVariables != null ? repoVariables : {})) {
256
+ for (const [key, value] of Object.entries(repoVariables ?? {})) {
259
257
  await client.rest.actions.createRepoVariable({
260
258
  owner,
261
259
  repo,
@@ -1319,6 +1317,7 @@ function createGithubWebhookAction(options) {
1319
1317
  id: "github:webhook",
1320
1318
  description: "Creates webhook for a repository on GitHub.",
1321
1319
  examples: examples$5,
1320
+ supportsDryRun: true,
1322
1321
  schema: {
1323
1322
  input: {
1324
1323
  type: "object",
@@ -1406,6 +1405,10 @@ function createGithubWebhookAction(options) {
1406
1405
  token: providedToken
1407
1406
  })
1408
1407
  );
1408
+ if (ctx.isDryRun) {
1409
+ ctx.logger.info(`Dry run complete`);
1410
+ return;
1411
+ }
1409
1412
  try {
1410
1413
  const insecure_ssl = insecureSsl ? "1" : "0";
1411
1414
  await client.rest.repos.createWebhook({
@@ -1734,7 +1737,7 @@ function createGithubEnvironmentAction(options) {
1734
1737
  owner,
1735
1738
  repo,
1736
1739
  environment_name: name,
1737
- deployment_branch_policy: deploymentBranchPolicy != null ? deploymentBranchPolicy : null
1740
+ deployment_branch_policy: deploymentBranchPolicy ?? null
1738
1741
  });
1739
1742
  if (customBranchPolicyNames) {
1740
1743
  for (const item of customBranchPolicyNames) {
@@ -1746,7 +1749,7 @@ function createGithubEnvironmentAction(options) {
1746
1749
  });
1747
1750
  }
1748
1751
  }
1749
- for (const [key, value] of Object.entries(environmentVariables != null ? environmentVariables : {})) {
1752
+ for (const [key, value] of Object.entries(environmentVariables ?? {})) {
1750
1753
  await client.rest.actions.createEnvironmentVariable({
1751
1754
  repository_id: repository.data.id,
1752
1755
  environment_name: name,
@@ -2072,6 +2075,7 @@ const createPublishGithubPullRequestAction = (options) => {
2072
2075
  return pluginScaffolderNode.createTemplateAction({
2073
2076
  id: "publish:github:pull-request",
2074
2077
  examples: examples$2,
2078
+ supportsDryRun: true,
2075
2079
  schema: {
2076
2080
  input: {
2077
2081
  required: ["repoUrl", "title", "description", "branchName"],
@@ -2187,7 +2191,6 @@ const createPublishGithubPullRequestAction = (options) => {
2187
2191
  }
2188
2192
  },
2189
2193
  async handler(ctx) {
2190
- var _a;
2191
2194
  const {
2192
2195
  repoUrl,
2193
2196
  branchName,
@@ -2220,7 +2223,7 @@ const createPublishGithubPullRequestAction = (options) => {
2220
2223
  repo,
2221
2224
  token: providedToken
2222
2225
  });
2223
- const fileRoot = sourcePath ? backendCommon.resolveSafeChildPath(ctx.workspacePath, sourcePath) : ctx.workspacePath;
2226
+ const fileRoot = sourcePath ? backendPluginApi.resolveSafeChildPath(ctx.workspacePath, sourcePath) : ctx.workspacePath;
2224
2227
  const directoryContents = await pluginScaffolderNode.serializeDirectoryContents(fileRoot, {
2225
2228
  gitignore: true
2226
2229
  });
@@ -2251,6 +2254,14 @@ const createPublishGithubPullRequestAction = (options) => {
2251
2254
  }
2252
2255
  ])
2253
2256
  );
2257
+ if (ctx.isDryRun) {
2258
+ ctx.logger.info(`Performing dry run of creating pull request`);
2259
+ ctx.output("targetBranchName", branchName);
2260
+ ctx.output("remoteUrl", repoUrl);
2261
+ ctx.output("pullRequestNumber", 43);
2262
+ ctx.logger.info(`Dry run complete`);
2263
+ return;
2264
+ }
2254
2265
  try {
2255
2266
  const createOptions = {
2256
2267
  owner,
@@ -2259,7 +2270,7 @@ const createPublishGithubPullRequestAction = (options) => {
2259
2270
  changes: [
2260
2271
  {
2261
2272
  files,
2262
- commit: (_a = commitMessage != null ? commitMessage : config == null ? void 0 : config.getOptionalString("scaffolder.defaultCommitMessage")) != null ? _a : title
2273
+ commit: commitMessage ?? config?.getOptionalString("scaffolder.defaultCommitMessage") ?? title
2263
2274
  }
2264
2275
  ],
2265
2276
  body: description,
@@ -2269,8 +2280,8 @@ const createPublishGithubPullRequestAction = (options) => {
2269
2280
  forceFork
2270
2281
  };
2271
2282
  const gitAuthorInfo = {
2272
- name: gitAuthorName != null ? gitAuthorName : config == null ? void 0 : config.getOptionalString("scaffolder.defaultAuthor.name"),
2273
- email: gitAuthorEmail != null ? gitAuthorEmail : config == null ? void 0 : config.getOptionalString("scaffolder.defaultAuthor.email")
2283
+ name: gitAuthorName ?? config?.getOptionalString("scaffolder.defaultAuthor.name"),
2284
+ email: gitAuthorEmail ?? config?.getOptionalString("scaffolder.defaultAuthor.email")
2274
2285
  };
2275
2286
  if (gitAuthorInfo.name || gitAuthorInfo.email) {
2276
2287
  if (Array.isArray(createOptions.changes)) {
@@ -2319,7 +2330,6 @@ const createPublishGithubPullRequestAction = (options) => {
2319
2330
  }
2320
2331
  });
2321
2332
  async function requestReviewersOnPullRequest(pr, reviewers, teamReviewers, client, logger) {
2322
- var _a, _b, _c, _d;
2323
2333
  try {
2324
2334
  const result = await client.rest.pulls.requestReviewers({
2325
2335
  owner: pr.owner,
@@ -2328,8 +2338,8 @@ const createPublishGithubPullRequestAction = (options) => {
2328
2338
  reviewers,
2329
2339
  team_reviewers: teamReviewers ? [...new Set(teamReviewers)] : void 0
2330
2340
  });
2331
- const addedUsers = (_b = (_a = result.data.requested_reviewers) == null ? void 0 : _a.join(", ")) != null ? _b : "";
2332
- const addedTeams = (_d = (_c = result.data.requested_teams) == null ? void 0 : _c.join(", ")) != null ? _d : "";
2341
+ const addedUsers = result.data.requested_reviewers?.join(", ") ?? "";
2342
+ const addedTeams = result.data.requested_teams?.join(", ") ?? "";
2333
2343
  logger.info(
2334
2344
  `Added users [${addedUsers}] and teams [${addedTeams}] as reviewers to Pull request ${pr.number}`
2335
2345
  );
@@ -2554,7 +2564,7 @@ function createPublishGithubAction(options) {
2554
2564
  dismissStaleReviews,
2555
2565
  requiredCommitSigning
2556
2566
  );
2557
- ctx.output("commitHash", commitResult == null ? void 0 : commitResult.commitHash);
2567
+ ctx.output("commitHash", commitResult?.commitHash);
2558
2568
  ctx.output("remoteUrl", remoteUrl);
2559
2569
  ctx.output("repoContentsUrl", repoContentsUrl);
2560
2570
  }