-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad43b6c
commit ade29e2
Showing
10 changed files
with
137 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { useMemo } from 'react'; | ||
import { forwardRef } from 'react'; | ||
|
||
import { HTMLStyledProps, styled } from 'leather-styles/jsx'; | ||
|
||
import { BRANCH_NAME, COMMIT_SHA } from '@shared/environment'; | ||
|
||
import { openInNewTab } from '@app/common/utils/open-in-new-tab'; | ||
import { useIsLatestPullRequestBuild } from '@app/query/common/outdated-pr/outdated-pr.query'; | ||
|
||
import { Tooltip } from './tooltip'; | ||
|
||
interface AppVersionLabelProps extends HTMLStyledProps<'span'> { | ||
isLatestVersion: boolean; | ||
} | ||
const AppVersionLabel = forwardRef<HTMLSpanElement, AppVersionLabelProps>( | ||
({ children, isLatestVersion, ...props }: AppVersionLabelProps, ref) => ( | ||
<styled.span | ||
ref={ref} | ||
textStyle="mono" | ||
fontSize="10px" | ||
marginRight="10px" | ||
mb="-4px" | ||
ml="tight" | ||
opacity={0.5} | ||
textDecoration={isLatestVersion ? 'none' : 'line-through'} | ||
{...props} | ||
> | ||
{children} | ||
</styled.span> | ||
) | ||
); | ||
|
||
export function AppVersion() { | ||
const { pullRequestLink, isLatestBuild } = useIsLatestPullRequestBuild(); | ||
|
||
const version = useMemo(() => { | ||
// eslint-disable-next-line no-console | ||
console.log('process.env.WALLET_ENVIRONMENT', process.env.WALLET_ENVIRONMENT); | ||
switch (process.env.WALLET_ENVIRONMENT) { | ||
case 'development': | ||
return `dev@${BRANCH_NAME}`; | ||
case 'feature': | ||
return `${BRANCH_NAME}#${COMMIT_SHA?.slice(0, 8)}`; | ||
default: | ||
return `v${VERSION}`; | ||
} | ||
}, []); | ||
|
||
if (!isLatestBuild && process.env.WALLET_ENVIRONMENT === 'feature') { | ||
return ( | ||
<Tooltip label="Outdated PR build, download the latest version"> | ||
<AppVersionLabel | ||
isLatestVersion={false} | ||
cursor="pointer" | ||
onClick={() => openInNewTab(pullRequestLink ?? '')} | ||
> | ||
{version} | ||
</AppVersionLabel> | ||
</Tooltip> | ||
); | ||
} | ||
|
||
return <AppVersionLabel isLatestVersion>{version}</AppVersionLabel>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,40 @@ | ||
import { Endpoints } from '@octokit/types'; | ||
import type { Endpoints } from '@octokit/types'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import axios from 'axios'; | ||
|
||
import { GITHUB_ORG, GITHUB_REPO } from '@shared/constants'; | ||
import { COMMIT_SHA, PR_NUMBER } from '@shared/environment'; | ||
import { isDefined } from '@shared/utils'; | ||
|
||
type PrInfoResp = Endpoints['GET /repos/{owner}/{repo}/pulls/{pull_number}']['response']; | ||
type PrDetailsResp = Endpoints['GET /repos/{owner}/{repo}/pulls/{pull_number}']['response']['data']; | ||
|
||
async function getPullRequestDetails(pr: string): Promise<PrInfoResp> { | ||
return axios.get(`https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/pulls/${pr}`); | ||
async function getPullRequestDetails(pr: string): Promise<PrDetailsResp> { | ||
const resp = await axios.get( | ||
`https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/pulls/${pr}` | ||
); | ||
|
||
return resp.data; | ||
} | ||
|
||
export function useIsOutdatedPrQuery() { | ||
function usePullRequestDetailsQuery() { | ||
return useQuery({ | ||
enabled: isDefined(PR_NUMBER) && isDefined(COMMIT_SHA), | ||
queryKey: ['outdated-pr-', PR_NUMBER], | ||
queryKey: ['pull-request-details', PR_NUMBER], | ||
async queryFn() { | ||
return getPullRequestDetails(PR_NUMBER ?? ''); | ||
}, | ||
select(resp) { | ||
return resp.data.head.sha.startsWith(COMMIT_SHA ?? ''); | ||
}, | ||
}); | ||
} | ||
|
||
export function useIsLatestPullRequestBuild() { | ||
const { data: pullRequest } = usePullRequestDetailsQuery(); | ||
if (!pullRequest) return { isLatestBuild: true }; | ||
// eslint-disable-next-line no-console | ||
console.log('debug info', { fromGithubApi: pullRequest.head.sha, fromEnv: COMMIT_SHA }); | ||
return { | ||
// If the latest commit SHA on the PR is not the same one used for this build, | ||
// we can assume it's outdated | ||
isLatestBuild: pullRequest.head.sha.startsWith(COMMIT_SHA ?? ''), | ||
pullRequestLink: pullRequest.html_url, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10767,10 +10767,10 @@ depd@~1.1.2: | |
resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9" | ||
integrity sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ== | ||
|
||
[email protected].0: | ||
version "14.1.0" | ||
resolved "https://registry.yarnpkg.com/dependency-cruiser/-/dependency-cruiser-14.1.0.tgz#7312f17e905f6183e3e47298ed2019b20534b217" | ||
integrity sha512-JF7F0SFG4K5vXmUMvgYHKQnMuU2JzO18/+r/hTuaGEr3KTlMYkR16WNc+WDqS0y5fjq8khDy/WKO4bR5xhw2sQ== | ||
[email protected].1: | ||
version "14.1.1" | ||
resolved "https://registry.yarnpkg.com/dependency-cruiser/-/dependency-cruiser-14.1.1.tgz#8d466ebe69af7c85af3670ba947c7b196d23260d" | ||
integrity sha512-npNLWv11pMH9BW4GBLuA5p6KYOXA9UjVDKQ4DzorEhAac5BS1J23K5I2WpEfkJMpwl9PKMsF4T/GDLSq3pogTw== | ||
dependencies: | ||
acorn "8.10.0" | ||
acorn-jsx "5.3.2" | ||
|
@@ -10796,7 +10796,7 @@ [email protected]: | |
semver-try-require "6.2.3" | ||
teamcity-service-messages "0.1.14" | ||
tsconfig-paths-webpack-plugin "4.1.0" | ||
watskeburt "1.0.1" | ||
watskeburt "2.0.0" | ||
wrap-ansi "8.1.0" | ||
|
||
dequal@^2.0.0: | ||
|
@@ -20207,10 +20207,10 @@ [email protected], watchpack@^2.4.0: | |
glob-to-regexp "^0.4.1" | ||
graceful-fs "^4.1.2" | ||
|
||
watskeburt@1.0.1: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/watskeburt/-/watskeburt-1.0.1.tgz#157e87319cedac222c2524e138136fad70ba253e" | ||
integrity sha512-MOvC8vf3hAVo1HPF/pkba7065mt6A/P9unLlFvYhZ7Yyuht16tmfCYi/LqHABG4hIRMZCbvY8eDWHPy81eSADA== | ||
watskeburt@2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/watskeburt/-/watskeburt-2.0.0.tgz#9599978fdf3c994354390bac7ca368726b6771ac" | ||
integrity sha512-RJ961Bcw9sfHr1NqZwvcFBYWo6bN9xE1CeBy6LigLqpzzrdnvsMT5HFg2JhOe4ioDOrCndjNa3tsErIVZtCc3g== | ||
|
||
wbuf@^1.1.0, wbuf@^1.7.3: | ||
version "1.7.3" | ||
|