Skip to content

Commit

Permalink
feat: Adjust preview links name to integrate them with Linear (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
macko911 authored Oct 14, 2024
1 parent 06e4e16 commit d058db3
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 13 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
required: false
description: "Name of the app, displayed in PR description"
type: string
app_icon:
required: false
description: "Icon of the app, displayed in PR description"
type: string
bundle_uri:
required: true
description: "S3 URI of the bundle in the registry bucket"
Expand Down Expand Up @@ -172,9 +176,11 @@ jobs:
if: ${{ github.event_name == 'pull_request' && steps.is-version-already-deployed.outputs.is_deployed == 'false' }}
with:
app_name: ${{ inputs.app_name }}
app_icon: ${{ inputs.app_icon }}
as_labels: true
links: |
[
{"name": "Latest", "url": "https://${{ steps.cursor-update.outputs.branch_label }}.${{ inputs.domain_name }}"},
{"name": "${{ inputs.app_name }} preview", "url": "https://${{ steps.cursor-update.outputs.branch_label }}.${{ inputs.domain_name }}"},
{"name": "Current Permalink", "url": "${{ steps.deployment-url.outputs.url }}"}
]
Expand Down
6 changes: 4 additions & 2 deletions actions/post-preview-urls/dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24270,17 +24270,19 @@ runAction(async () => {
const token = core2.getInput("token", { required: true });
const linksJSON = core2.getInput("links", { required: true });
const appName = core2.getInput("app_name", { required: true });
const appIcon = core2.getInput("app_icon");
const asLabels = core2.getInput("as_labels") === "true";
const repo = github.context.repo;
const prNumber = (_a2 = github.context.payload.pull_request) == null ? void 0 : _a2.number;
await postPreviewUrls({ linksJSON, token, prNumber, repo, appName, asLabels });
await postPreviewUrls({ linksJSON, token, prNumber, repo, appName, appIcon, asLabels });
});
async function postPreviewUrls({
token,
linksJSON,
repo,
prNumber,
appName,
appIcon,
asLabels
}) {
var _a2, _b;
Expand All @@ -24305,7 +24307,7 @@ async function postPreviewUrls({
}
return `_${link.name}_: ${link.url}`;
}).join(asLabels ? ", " : "\n");
const heading = `**${appName} preview links**`;
const heading = `**${[appIcon, appName].join(" ").trim()} preview links**`;
const body = [
prDescriptionAbove + descriptionAppendage,
markerStart,
Expand Down
65 changes: 58 additions & 7 deletions actions/post-preview-urls/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ describe(`Post Preview URLs action`, () => {
token,
repo: {owner: 'my-org', repo: 'my-repo'},
prNumber: 1,
appName: '🤖 App'
appIcon: '🤖',
appName: 'App'
})

expect(mockedGithub.getOctokit).toBeCalledWith(token)
Expand Down Expand Up @@ -79,7 +80,8 @@ describe(`Post Preview URLs action`, () => {
token,
repo: {owner: 'my-org', repo: 'my-repo'},
prNumber: 1,
appName: '🤖 App',
appIcon: '🤖',
appName: 'App',
asLabels: true
})

Expand Down Expand Up @@ -135,7 +137,8 @@ describe(`Post Preview URLs action`, () => {
token,
repo: {owner: 'my-org', repo: 'my-repo'},
prNumber: 1,
appName: '🤖 App'
appIcon: '🤖',
appName: 'App'
})

expect(mockedGithub.getOctokit).toBeCalledWith(token)
Expand Down Expand Up @@ -192,7 +195,8 @@ describe(`Post Preview URLs action`, () => {
token,
repo: {owner: 'my-org', repo: 'my-repo'},
prNumber: 1,
appName: '🤖 App'
appIcon: '🤖',
appName: 'App'
})

expect(mockedGithub.getOctokit).toBeCalledWith(token)
Expand Down Expand Up @@ -253,7 +257,8 @@ describe(`Post Preview URLs action`, () => {
token,
repo: {owner: 'my-org', repo: 'my-repo'},
prNumber: 1,
appName: '🤖 Storybook'
appIcon: '🤖',
appName: 'Storybook'
})

expect(mockedGithub.getOctokit).toBeCalledWith(token)
Expand Down Expand Up @@ -327,7 +332,8 @@ describe(`Post Preview URLs action`, () => {
token,
repo: {owner: 'my-org', repo: 'my-repo'},
prNumber: 1,
appName: '📚 Storybook'
appIcon: '📚',
appName: 'Storybook'
})

expect(mockedGithub.getOctokit).toBeCalledWith(token)
Expand Down Expand Up @@ -375,7 +381,8 @@ describe(`Post Preview URLs action`, () => {
token,
repo: {owner: 'my-org', repo: 'my-repo'},
prNumber: 1,
appName: '🤖 App'
appIcon: '🤖',
appName: 'App'
})

expect(mockedGithub.getOctokit).toBeCalledWith(token)
Expand All @@ -399,4 +406,48 @@ describe(`Post Preview URLs action`, () => {
)
}
)

test(
strip`
When there is no app icon
There is no space before the app name
`,
async () => {
const token = '1234'
const mockRequest = jest.fn().mockResolvedValueOnce({
data: {body: 'Hello World!\n Some indent'}
})
mockedGithub.getOctokit.mockReturnValue({request: mockRequest} as any)

await postPreviewUrls({
linksJSON: JSON.stringify([
{name: 'Latest', url: 'https://feature.app.example.com'}
]),
token,
repo: {owner: 'my-org', repo: 'my-repo'},
prNumber: 1,
appName: 'App'
})

expect(mockedGithub.getOctokit).toBeCalledWith(token)
expect(mockRequest).toHaveBeenLastCalledWith(
'PATCH /repos/{owner}/{repo}/pulls/{pull_number}',
{
body: strip`
Hello World!
Some indent
<!--app-preview-urls-do-not-change-below-->
---
**App preview links**
_Latest_: https://feature.app.example.com
<!--app-preview-urls-do-not-change-above-->
`,
owner: 'my-org',
pull_number: 1,
repo: 'my-repo'
}
)
}
)
})
7 changes: 5 additions & 2 deletions actions/post-preview-urls/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ runAction(async () => {
const token = core.getInput('token', {required: true})
const linksJSON = core.getInput('links', {required: true})
const appName = core.getInput('app_name', {required: true})
const appIcon = core.getInput('app_icon')
const asLabels = core.getInput('as_labels') === 'true'
const repo = github.context.repo
const prNumber = github.context.payload.pull_request?.number

await postPreviewUrls({linksJSON, token, prNumber, repo, appName, asLabels})
await postPreviewUrls({linksJSON, token, prNumber, repo, appName, appIcon, asLabels})
})

interface PostPreviewUrlsActionArgs {
token: string
prNumber?: number
repo: typeof github.context.repo
appName: string
appIcon?: string
linksJSON: string
asLabels?: boolean
}
Expand All @@ -33,6 +35,7 @@ export async function postPreviewUrls({
repo,
prNumber,
appName,
appIcon,
asLabels
}: PostPreviewUrlsActionArgs) {
if (!prNumber) {
Expand Down Expand Up @@ -63,7 +66,7 @@ export async function postPreviewUrls({
return `_${link.name}_: ${link.url}`
})
.join(asLabels ? ', ' : '\n')
const heading = `**${appName} preview links**`
const heading = `**${[appIcon, appName].join(' ').trim()} preview links**`

const body = [
prDescriptionAbove + descriptionAppendage,
Expand Down
8 changes: 7 additions & 1 deletion reusable-workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
required: false
description: "Name of the app, displayed in PR description"
type: string
app_icon:
required: false
description: "Icon of the app, displayed in PR description"
type: string
bundle_uri:
required: true
description: "S3 URI of the bundle in the registry bucket"
Expand Down Expand Up @@ -172,9 +176,11 @@ jobs:
if: ${{ github.event_name == 'pull_request' && steps.is-version-already-deployed.outputs.is_deployed == 'false' }}
with:
app_name: ${{ inputs.app_name }}
app_icon: ${{ inputs.app_icon }}
as_labels: true
links: |
[
{"name": "Latest", "url": "https://${{ steps.cursor-update.outputs.branch_label }}.${{ inputs.domain_name }}"},
{"name": "${{ inputs.app_name }} preview", "url": "https://${{ steps.cursor-update.outputs.branch_label }}.${{ inputs.domain_name }}"},
{"name": "Current Permalink", "url": "${{ steps.deployment-url.outputs.url }}"}
]
Expand Down

0 comments on commit d058db3

Please sign in to comment.