@teambit/ci 1.0.637 → 1.0.639

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/ci.docs.mdx CHANGED
@@ -243,16 +243,22 @@ bit ci sync --init
243
243
  ```
244
244
 
245
245
  `--init` writes `.github/workflows/bit-sync.yml` and `bit-release.yml`, with the real default branch of this
246
- repository in both files. `--init` adds `"teambit.git/ci": { "sync": {} }` to `workspace.jsonc` if the key is
246
+ repository in both files. When the workspace is below the repository root, `--init` writes the files at the
247
+ root and sets `ws-dir` to the workspace directory in both. `--init` adds `"teambit.git/ci": { "sync": {} }` to `workspace.jsonc` if the key is
247
248
  absent. The edit keeps the comments in the file, and it changes no existing `sync` setting. `--init` then
248
- prints the steps that need a person:
249
+ prints one short report: the files it changed, and three steps that need a person, as commands to paste:
249
250
 
250
- - the `BIT_CONFIG_ACCESS_TOKEN` secret
251
- - the optional `BIT_SYNC_GH_TOKEN` token
252
- - the bit.cloud webhook recipe
253
- - a `fetch-depth: 0` reminder
251
+ 1. Commit the files `--init` changed, and push. With no `origin`, create the repository with `gh repo create`.
252
+ 2. Set the `BIT_CONFIG_ACCESS_TOKEN` secret, allow GitHub Actions to open pull requests, and optionally set
253
+ the `BIT_SYNC_GH_TOKEN` secret.
254
+ 3. Optional: make Bit -> Git instant. On github.com, install the `bit-git-sync` GitHub App and add its
255
+ webhook URL to the scope. On GitHub Enterprise Server, add a webhook that calls the repository
256
+ `dispatches` API.
254
257
 
255
- `--init` reports an existing file as skipped, and overwrites no file, so a second run is safe. `--init`
258
+ The commands name the repository of `origin`. When `origin` is not a GitHub remote yet, `--init` prints
259
+ only the push step, then tells you to run `--init` again after you push.
260
+
261
+ `--init` reports an existing file as unchanged, and overwrites no file, so a second run is safe. `--init`
256
262
  writes the files, then exits. Do not combine `--init` with a lane argument or with another flag.
257
263
 
258
264
  ### Usage
@@ -61,9 +61,12 @@ export class CiSyncCmd implements Command {
61
61
  // `[lane]: [string]` rather than `[string?]`: `CLIArgs` does not admit an undefined-carrying tuple.
62
62
  // The argument is genuinely optional at runtime, hence the `|| undefined` below.
63
63
  async report([lane]: [string], options: Options) {
64
- this.logger.console('\n\n');
65
- this.logger.console('Initializing sync command');
66
64
  if (!this.workspace) throw new OutsideWorkspaceError();
65
+ // --init prints its own report; the banner only frames a reconcile run.
66
+ if (!options.init) {
67
+ this.logger.console('\n\n');
68
+ this.logger.console('Initializing sync command');
69
+ }
67
70
 
68
71
  return this.ci.sync({
69
72
  lane: lane || undefined,
package/dist/ci.docs.mdx CHANGED
@@ -243,16 +243,22 @@ bit ci sync --init
243
243
  ```
244
244
 
245
245
  `--init` writes `.github/workflows/bit-sync.yml` and `bit-release.yml`, with the real default branch of this
246
- repository in both files. `--init` adds `"teambit.git/ci": { "sync": {} }` to `workspace.jsonc` if the key is
246
+ repository in both files. When the workspace is below the repository root, `--init` writes the files at the
247
+ root and sets `ws-dir` to the workspace directory in both. `--init` adds `"teambit.git/ci": { "sync": {} }` to `workspace.jsonc` if the key is
247
248
  absent. The edit keeps the comments in the file, and it changes no existing `sync` setting. `--init` then
248
- prints the steps that need a person:
249
+ prints one short report: the files it changed, and three steps that need a person, as commands to paste:
249
250
 
250
- - the `BIT_CONFIG_ACCESS_TOKEN` secret
251
- - the optional `BIT_SYNC_GH_TOKEN` token
252
- - the bit.cloud webhook recipe
253
- - a `fetch-depth: 0` reminder
251
+ 1. Commit the files `--init` changed, and push. With no `origin`, create the repository with `gh repo create`.
252
+ 2. Set the `BIT_CONFIG_ACCESS_TOKEN` secret, allow GitHub Actions to open pull requests, and optionally set
253
+ the `BIT_SYNC_GH_TOKEN` secret.
254
+ 3. Optional: make Bit -> Git instant. On github.com, install the `bit-git-sync` GitHub App and add its
255
+ webhook URL to the scope. On GitHub Enterprise Server, add a webhook that calls the repository
256
+ `dispatches` API.
254
257
 
255
- `--init` reports an existing file as skipped, and overwrites no file, so a second run is safe. `--init`
258
+ The commands name the repository of `origin`. When `origin` is not a GitHub remote yet, `--init` prints
259
+ only the push step, then tells you to run `--init` again after you push.
260
+
261
+ `--init` reports an existing file as unchanged, and overwrites no file, so a second run is safe. `--init`
256
262
  writes the files, then exits. Do not combine `--init` with a lane argument or with another flag.
257
263
 
258
264
  ### Usage
@@ -137,14 +137,16 @@ export declare class CiMain {
137
137
  convertBranchToLaneId(branchName: string): string;
138
138
  /**
139
139
  * The repository's default branch name, whole — slashes included (see `parseOriginHeadRef`).
140
- * Local `origin/HEAD` symref first, then the remote's own answer, then the conventional probe.
140
+ * What `detectDefaultBranchName` finds, else `master`, with a warning that names it.
141
141
  */
142
142
  getDefaultBranchName(): Promise<string>;
143
143
  /**
144
- * Last-resort fallback: the two conventional names among the remote branches, then `master`.
145
- * Deliberately only `main`/`master` — any wider guess risks protecting the wrong branch.
144
+ * The default branch as the repository itself states it: the local `origin/HEAD` symref, then the
145
+ * remote's own answer, then `main`/`master` among the remote branches. Undefined when none of them
146
+ * answers (no origin, a repository not pushed yet, a server out of reach), so a caller can tell a
147
+ * detected branch from a guess.
146
148
  */
147
- private probeDefaultBranchName;
149
+ detectDefaultBranchName(): Promise<string | undefined>;
148
150
  getGitCommitMessage(): Promise<string | null>;
149
151
  private parseVersionBumpFromCommit;
150
152
  private getCustomCommitMessage;
@@ -423,9 +423,22 @@ class CiMain {
423
423
 
424
424
  /**
425
425
  * The repository's default branch name, whole — slashes included (see `parseOriginHeadRef`).
426
- * Local `origin/HEAD` symref first, then the remote's own answer, then the conventional probe.
426
+ * What `detectDefaultBranchName` finds, else `master`, with a warning that names it.
427
427
  */
428
428
  async getDefaultBranchName() {
429
+ const detected = await this.detectDefaultBranchName();
430
+ if (detected) return detected;
431
+ this.logger.console(_chalk().default.yellow(`Unable to detect default branch, using 'master'`));
432
+ return 'master';
433
+ }
434
+
435
+ /**
436
+ * The default branch as the repository itself states it: the local `origin/HEAD` symref, then the
437
+ * remote's own answer, then `main`/`master` among the remote branches. Undefined when none of them
438
+ * answers (no origin, a repository not pushed yet, a server out of reach), so a caller can tell a
439
+ * detected branch from a guess.
440
+ */
441
+ async detectDefaultBranchName() {
429
442
  try {
430
443
  const result = await _git().git.raw(['symbolic-ref', 'refs/remotes/origin/HEAD']);
431
444
  const local = (0, _gitOps().parseOriginHeadRef)(result);
@@ -438,23 +451,16 @@ class CiMain {
438
451
  }
439
452
  const remote = await (0, _gitOps().remoteHeadBranch)();
440
453
  if (remote && (0, _syncConfig().isValidGitBranchName)(remote)) return remote;
441
- return this.probeDefaultBranchName();
442
- }
443
-
444
- /**
445
- * Last-resort fallback: the two conventional names among the remote branches, then `master`.
446
- * Deliberately only `main`/`master` — any wider guess risks protecting the wrong branch.
447
- */
448
- async probeDefaultBranchName(originalError) {
454
+ // Deliberately only `main`/`master` — any wider guess risks protecting the wrong branch.
449
455
  try {
450
456
  const branches = await _git().git.branch(['-r']);
451
457
  if (branches.all.includes('origin/main')) return 'main';
452
458
  if (branches.all.includes('origin/master')) return 'master';
453
- return 'master';
454
- } catch {
455
- this.logger.console(_chalk().default.yellow(`Unable to detect default branch, using 'master'${originalError ? `: ${originalError}` : ''}`));
456
- return 'master';
459
+ } catch (err) {
460
+ // debug only: the caller decides what to say, and what to use instead
461
+ this.logger.debug(`detectDefaultBranchName: "git branch -r" failed: ${err.message}`);
457
462
  }
463
+ return undefined;
458
464
  }
459
465
  async getGitCommitMessage() {
460
466
  try {