runcloud 0.2.179 → 0.2.180

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.
@@ -0,0 +1,61 @@
1
+ import { ApiClient, ApiError, friendlyApiError } from '../api.js';
2
+ import { requireCredentials, resolveProject } from '../config.js';
3
+ export async function getGithubStatus(client, projectId) {
4
+ return (await client.get(`/projects/${encodeURIComponent(projectId)}/github/status?ahead=1`));
5
+ }
6
+ export async function pullGithubBranch(client, projectId, branch) {
7
+ await client.post(`/projects/${encodeURIComponent(projectId)}/git/branches/${encodeURIComponent(branch)}/push`);
8
+ }
9
+ export function formatGithubBranches(status) {
10
+ if (!status.connected)
11
+ return 'This project is not linked to a GitHub repository.';
12
+ const repo = `${status.owner}/${status.name}`;
13
+ if (status.ahead === undefined)
14
+ return `Linked to ${repo}, but GitHub could not be read right now. Try again shortly.`;
15
+ if (status.ahead.length === 0)
16
+ return `Linked to ${repo}. Newly has every GitHub branch at its current tip.`;
17
+ return [
18
+ `Linked to ${repo}. On GitHub, not yet in Newly at their current tip:`,
19
+ ...status.ahead.map((b) => ` ${b}`),
20
+ 'Bring one in with: newly github pull <branch>',
21
+ ].join('\n');
22
+ }
23
+ export function registerGithub(program) {
24
+ const github = program
25
+ .command('github')
26
+ .description("Work with the project's linked GitHub repository");
27
+ const run = (action) => async (opts) => {
28
+ try {
29
+ const creds = requireCredentials();
30
+ const projectId = resolveProject(process.cwd(), opts.project);
31
+ await action(new ApiClient(creds.apiUrl, creds.token), projectId);
32
+ }
33
+ catch (e) {
34
+ console.error(friendlyApiError(e));
35
+ process.exitCode = 1;
36
+ }
37
+ };
38
+ github
39
+ .command('branches')
40
+ .description('List GitHub branches that Newly does not have yet (or has at an older tip)')
41
+ .option('--project <id>', 'project id (defaults to the linked directory)')
42
+ .action(run(async (client, projectId) => {
43
+ console.log(formatGithubBranches(await getGithubStatus(client, projectId)));
44
+ }));
45
+ github
46
+ .command('pull <branch>')
47
+ .description('Bring one GitHub branch into Newly (a two-way sync of that branch) so it can be fetched and checked out')
48
+ .option('--project <id>', 'project id (defaults to the linked directory)')
49
+ .action((branch, opts) => run(async (client, projectId) => {
50
+ try {
51
+ await pullGithubBranch(client, projectId, branch);
52
+ }
53
+ catch (e) {
54
+ if (e instanceof ApiError && e.status === 403) {
55
+ throw new Error(`Pulling ${branch} needs a project admin. Ask the user to pull it from the GitHub pane in the Deploy tab.`);
56
+ }
57
+ throw e;
58
+ }
59
+ console.log(`${branch} is in Newly, synced both ways with GitHub. Run: git fetch origin ${branch} && git checkout ${branch}`);
60
+ })(opts));
61
+ }
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ import { registerPull } from './commands/pull.js';
10
10
  import { registerDeploy } from './commands/deploy.js';
11
11
  import { registerMisc } from './commands/misc.js';
12
12
  import { registerStack } from './commands/stack.js';
13
+ import { registerGithub } from './commands/github.js';
13
14
  import { registerCreds } from './commands/creds.js';
14
15
  import { registerBuild } from './commands/build.js';
15
16
  import { registerServices } from './commands/services.js';
@@ -37,6 +38,7 @@ registerDeploy(program);
37
38
  registerAi(program);
38
39
  registerMisc(program);
39
40
  registerStack(program);
41
+ registerGithub(program);
40
42
  registerCreds(program);
41
43
  registerBuild(program);
42
44
  registerServices(program);
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = '0.2.179';
1
+ export const CLI_VERSION = '0.2.180';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runcloud",
3
- "version": "0.2.179",
3
+ "version": "0.2.180",
4
4
  "description": "Create and control run.cloud remote mobile simulators and cloud sandboxes",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
Binary file
Binary file