Skip to content

Commit 2603f85

Browse files
authored
feature: add projectDeepLink to template variables (#165)
* feat: added projectDeepLink to template variables * fix: updates from code review
1 parent 520d959 commit 2603f85

6 files changed

Lines changed: 73 additions & 14 deletions

File tree

build/preview-comment/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15785,6 +15785,7 @@ async function commentAction(input = commentInput()) {
1578515785
}
1578615786
const variables = {
1578715787
projectLink: (0, expo_1.projectLink)(project, input.channel),
15788+
projectDeepLink: (0, expo_1.projectDeepLink)(project, input.channel),
1578815789
projectName: project.name,
1578915790
projectOwner: project.owner || '',
1579015791
projectQR: (0, expo_1.projectQR)(project, input.channel),
@@ -15828,7 +15829,7 @@ function template(template, replacements) {
1582815829
"use strict";
1582915830

1583015831
Object.defineProperty(exports, "__esModule", ({ value: true }));
15831-
exports.projectLink = exports.projectQR = exports.projectInfo = exports.projectOwner = exports.authenticate = void 0;
15832+
exports.projectDeepLink = exports.projectLink = exports.projectQR = exports.projectInfo = exports.projectOwner = exports.authenticate = void 0;
1583215833
const core_1 = __nccwpck_require__(2186);
1583315834
const exec_1 = __nccwpck_require__(1514);
1583415835
const io_1 = __nccwpck_require__(7436);
@@ -15915,6 +15916,18 @@ function projectLink(project, channel) {
1591515916
return url.toString();
1591615917
}
1591715918
exports.projectLink = projectLink;
15919+
/**
15920+
* Create a deep link to open the project in Expo Go
15921+
*/
15922+
function projectDeepLink(project, channel) {
15923+
(0, assert_1.ok)(project.owner, 'Could not create a deep link for project without owner');
15924+
const url = new url_1.URL(`exp://exp.host/@${project.owner}/${project.slug}`);
15925+
if (channel) {
15926+
url.searchParams.append('release-channel', channel);
15927+
}
15928+
return url.toString();
15929+
}
15930+
exports.projectDeepLink = projectDeepLink;
1591815931

1591915932

1592015933
/***/ }),

build/setup/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66905,7 +66905,7 @@ exports.handleCacheError = handleCacheError;
6690566905
"use strict";
6690666906

6690766907
Object.defineProperty(exports, "__esModule", ({ value: true }));
66908-
exports.projectLink = exports.projectQR = exports.projectInfo = exports.projectOwner = exports.authenticate = void 0;
66908+
exports.projectDeepLink = exports.projectLink = exports.projectQR = exports.projectInfo = exports.projectOwner = exports.authenticate = void 0;
6690966909
const core_1 = __nccwpck_require__(2186);
6691066910
const exec_1 = __nccwpck_require__(1514);
6691166911
const io_1 = __nccwpck_require__(7436);
@@ -66992,6 +66992,18 @@ function projectLink(project, channel) {
6699266992
return url.toString();
6699366993
}
6699466994
exports.projectLink = projectLink;
66995+
/**
66996+
* Create a deep link to open the project in Expo Go
66997+
*/
66998+
function projectDeepLink(project, channel) {
66999+
(0, assert_1.ok)(project.owner, 'Could not create a deep link for project without owner');
67000+
const url = new url_1.URL(`exp://exp.host/@${project.owner}/${project.slug}`);
67001+
if (channel) {
67002+
url.searchParams.append('release-channel', channel);
67003+
}
67004+
return url.toString();
67005+
}
67006+
exports.projectDeepLink = projectDeepLink;
6699567007

6699667008

6699767009
/***/ }),

preview-comment/README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,17 @@ There are a few variables available to generate the comment content.
5252
Some of these variables are also exported as subaction output.
5353
Here is a summary of these variables.
5454

55-
| output name | template name | description |
56-
| ---------------- | ---------------- | ---------------------------------------------------- |
57-
| **projectOwner** | `{projectOwner}` | The resolved owner of the project |
58-
| **projectSlug** | `{projectSlug}` | The resolved slug of the project |
59-
| **projectName** | `{projectName}` | The resolved name of the project |
60-
| **projectLink** | `{projectLink}` | The expo.dev project link, including release channel |
61-
| **projectQR** | `{projectQR}` | The QR code link, to load the project in Expo Go |
62-
| - | `{channel}` | The release channel that was used |
63-
| **message** | - | The resolved message content |
64-
| **messageId** | - | The resolved message id content |
55+
| output name | template name | description |
56+
| ---------------- | ---------------- | ----------------------------------------------------- |
57+
| **projectOwner** | `{projectOwner}` | The resolved owner of the project |
58+
| **projectSlug** | `{projectSlug}` | The resolved slug of the project |
59+
| **projectName** | `{projectName}` | The resolved name of the project |
60+
| **projectDeepLink** | `{projectDeepLink}` | A deep link to open the project in Expo Go |
61+
| **projectLink** | `{projectLink}` | The expo.dev project link, including release channel |
62+
| **projectQR** | `{projectQR}` | The QR code link, to load the project in Expo Go |
63+
| - | `{channel}` | The release channel that was used |
64+
| **message** | - | The resolved message content |
65+
| **messageId** | - | The resolved message id content |
6566

6667
## Example workflows
6768

src/actions/preview-comment.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getBooleanInput, getInput, setOutput, info } from '@actions/core';
22

3-
import { projectInfo, projectLink, projectOwner, projectQR } from '../expo';
3+
import { projectDeepLink, projectInfo, projectLink, projectOwner, projectQR } from '../expo';
44
import { createIssueComment, pullContext } from '../github';
55
import { executeAction } from '../worker';
66

@@ -34,6 +34,7 @@ export async function commentAction(input: CommentInput = commentInput()) {
3434

3535
const variables: Record<string, string> = {
3636
projectLink: projectLink(project, input.channel),
37+
projectDeepLink: projectDeepLink(project, input.channel),
3738
projectName: project.name,
3839
projectOwner: project.owner || '',
3940
projectQR: projectQR(project, input.channel),

src/expo.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,17 @@ export function projectLink(project: ProjectInfo, channel?: string): string {
9898

9999
return url.toString();
100100
}
101+
102+
/**
103+
* Create a deep link to open the project in Expo Go
104+
*/
105+
export function projectDeepLink(project: ProjectInfo, channel?: string): string {
106+
assert(project.owner, 'Could not create a deep link for project without owner');
107+
108+
const url = new URL(`exp://exp.host/@${project.owner}/${project.slug}`);
109+
if (channel) {
110+
url.searchParams.append('release-channel', channel);
111+
}
112+
113+
return url.toString();
114+
}

tests/expo.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as core from '@actions/core';
22
import * as exec from '@actions/exec';
33
import * as io from '@actions/io';
44

5-
import { authenticate, projectQR, projectLink } from '../src/expo';
5+
import { authenticate, projectQR, projectLink, projectDeepLink } from '../src/expo';
66

77
jest.mock('@actions/core');
88
jest.mock('@actions/exec');
@@ -68,3 +68,21 @@ describe(projectLink, () => {
6868
);
6969
});
7070
});
71+
72+
describe(projectDeepLink, () => {
73+
it('throws when owner is undefined', () => {
74+
expect(() => projectDeepLink({ name: 'fakename', slug: 'fakeslug' })).toThrow('without owner');
75+
});
76+
77+
it('returns url with owner and slug', () => {
78+
expect(projectDeepLink({ name: 'fakename', slug: 'fakeslug', owner: 'fakeowner' })).toBe(
79+
'exp://exp.host/@fakeowner/fakeslug'
80+
);
81+
});
82+
83+
it('returns url with owner, slug, and release channel', () => {
84+
expect(projectDeepLink({ name: 'fakename', slug: 'fakeslug', owner: 'fakeowner' }, 'fakechannel')).toBe(
85+
'exp://exp.host/@fakeowner/fakeslug?release-channel=fakechannel'
86+
);
87+
});
88+
});

0 commit comments

Comments
 (0)