-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Github PR creation #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Xaroz
wants to merge
27
commits into
main
Choose a base branch
from
xaroz/feat/pr-creation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
ddc3643
feat: initial create PR setup
Xaroz 5631099
chore: move to useMutation
Xaroz a0cc2d4
chore: clean up
Xaroz a66e9f4
chore: improve typing and symbol check
Xaroz 135e379
chore: validate configs, clean up pr descriptions
Xaroz 72bee32
chore: include modal for adding PR, fix bug with modal close
Xaroz 3ff2d3f
feat: include username, org and clean up
Xaroz d37bb80
chore: move PR creation to success, clean up hard-coded index and lan…
Xaroz e9db236
feat: add changeset to commits
Xaroz 8a0fa46
chore: sort warp core config
Xaroz 007be59
chore: sort result in deployment details
Xaroz 1e000ce
chore: persist octokit instance, refactor json response and type
Xaroz 6b5dc38
chore: include warpRouteId to request
Xaroz 12d7a68
chore: move create PR types to its own file
Xaroz 3ac0888
chore: refactor body validation into its own fn
Xaroz 6cc9d0d
chore: move createPr types
Xaroz e97838c
chore: use warpRouteId for filenames
Xaroz 18f5a7f
chore: remove type assertion
Xaroz 0af1496
feat: verify create-pr request to prevent spamming (#31)
Xaroz cda7250
fix: wrong address for verification and assertion for warpRouteId
Xaroz 1f6a441
chore: change flow redirection
Xaroz add4bfd
chore: use viem for kekkach256
Xaroz 23c8fdd
fix: attempt to fix build by excluding rainbow kit
Xaroz f40f613
chore: attempt fix with standalone flag
Xaroz d67a700
chore: temporary remove addressEvmCheck
Xaroz 25d8f0e
chore: return redirect flow
Xaroz 5ae6b0d
chore: optimize imports
Xaroz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,46 @@ | ||
import { z } from 'zod'; | ||
|
||
export const ServerConfigSchema = z.object({ | ||
githubForkOwner: z | ||
.string() | ||
.min(1, 'GITHUB_FORK_OWNER is required') | ||
.describe('Username of the forked repository owner'), | ||
githubRepoName: z | ||
.string() | ||
.min(1, 'GITHUB_REPO is required') | ||
.describe('Name of the repository (should match both upstream and fork)'), | ||
githubUpstreamOwner: z | ||
.string() | ||
.min(1, 'GITHUB_UPSTREAM_OWNER is required') | ||
.describe('Username of the base (upstream) repository owner'), | ||
githubBaseBranch: z | ||
.string() | ||
.min(1, 'GITHUB_BASE_BRANCH is required') | ||
.describe('Branch of the repositories (e.g., main or master)'), | ||
githubToken: z | ||
.string() | ||
.min(1, 'GITHUB_TOKEN is required') | ||
.describe('GitHub token of the fork owner with repo/pull access'), | ||
serverEnvironment: z | ||
.string() | ||
.optional() | ||
.describe('The environment currently running on the server'), | ||
}); | ||
|
||
export type ServerConfig = z.infer<typeof ServerConfigSchema>; | ||
|
||
const githubForkOwner = process.env.GITHUB_FORK_OWNER || ''; | ||
const githubRepoName = process.env.GITHUB_REPO || ''; | ||
const githubUpstreamOwner = process.env.GITHUB_UPSTREAM_OWNER || ''; | ||
const githubBaseBranch = 'main'; | ||
const githubToken = process.env.GITHUB_TOKEN || ''; | ||
const serverEnvironment = process.env.SERVER_ENVIRONMENT || 'production'; | ||
|
||
export const serverConfig: ServerConfig = Object.freeze({ | ||
githubForkOwner, | ||
githubRepoName, | ||
githubUpstreamOwner, | ||
githubBaseBranch, | ||
githubToken, | ||
serverEnvironment, | ||
}); | ||
This file contains hidden or 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 hidden or 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,163 @@ | ||
import { ErrorIcon, Modal } from '@hyperlane-xyz/widgets'; | ||
import { Form, Formik, useFormikContext } from 'formik'; | ||
import { SolidButton } from '../../components/buttons/SolidButton'; | ||
import { TextInput } from '../../components/input/TextField'; | ||
import { A } from '../../components/text/A'; | ||
import { H2 } from '../../components/text/Headers'; | ||
import { links } from '../../consts/links'; | ||
import { Color } from '../../styles/Color'; | ||
import { CreatePrResponse, GithubIdentity, GitHubIdentitySchema } from '../../types/createPr'; | ||
import { normalizeEmptyStrings } from '../../utils/string'; | ||
import { zodErrorToFormikErrors } from '../../utils/zod'; | ||
|
||
export function CreateRegistryPrModal({ | ||
isOpen, | ||
onCancel, | ||
onConfirm, | ||
confirmDisabled, | ||
disabled, | ||
response, | ||
}: { | ||
isOpen: boolean; | ||
disabled: boolean; | ||
confirmDisabled: boolean; | ||
onCancel: () => void; | ||
onConfirm: (values: GithubIdentity) => void; | ||
response: CreatePrResponse | null | undefined; | ||
}) { | ||
return ( | ||
<Modal | ||
isOpen={isOpen} | ||
close={onCancel} | ||
panelClassname="p-4 flex flex-col items-center gap-4 max-w-xl" | ||
> | ||
<H2>Add this deployment to the Hyperlane Registry</H2> | ||
<p className={styles.text}> | ||
Would you like to create a Pull Request on Github to include this deployment to the{' '} | ||
<A className={styles.link} href={links.registry}> | ||
Hyperlane Registry | ||
</A> | ||
? Once your PR is merged, your artifacts will become available for the community to use! | ||
</p> | ||
|
||
<p className={styles.text}> | ||
Optionally, you can include your Github username and organization! | ||
</p> | ||
|
||
<Formik<GithubIdentity> | ||
onSubmit={onConfirm} | ||
validate={validateForm} | ||
validateOnChange={false} | ||
validateOnBlur={false} | ||
initialValues={{ organization: undefined, username: undefined }} | ||
> | ||
{() => ( | ||
<Form className="w-full"> | ||
{response && response.success ? ( | ||
<div className={`${styles.text} w-full`}> | ||
<p>This is the link to your PR:</p> | ||
<div className="w-full space-y-2 rounded-lg bg-blue-500/5 px-3 py-4"> | ||
<A className={styles.link} href={response.data.prUrl}> | ||
{response.data.prUrl} | ||
</A> | ||
</div> | ||
</div> | ||
) : ( | ||
<InputSection /> | ||
)} | ||
|
||
<ButtonsSection | ||
onCancel={onCancel} | ||
confirmDisabled={confirmDisabled} | ||
disabled={disabled} | ||
/> | ||
</Form> | ||
)} | ||
</Formik> | ||
</Modal> | ||
); | ||
} | ||
|
||
function InputSection() { | ||
const { setFieldValue, values, errors } = useFormikContext<GithubIdentity>(); | ||
|
||
return ( | ||
<div className="flex gap-4"> | ||
<div className="w-full"> | ||
<TextInput | ||
className="w-full" | ||
value={values.username ?? ''} | ||
onChange={(v) => setFieldValue('username', v)} | ||
placeholder="Github Username" | ||
/> | ||
{errors.username && ( | ||
<div className="flex items-center gap-2 px-3 py-1.5"> | ||
<ErrorIcon width={14} height={14} color={Color.red['600']} className="shrink-0" /> | ||
<span className="text-xs text-red-600">{errors.username}</span> | ||
</div> | ||
)} | ||
</div> | ||
<div className="w-full"> | ||
<TextInput | ||
className="w-full" | ||
value={values.organization ?? ''} | ||
onChange={(v) => setFieldValue('organization', v)} | ||
placeholder="Organization" | ||
/> | ||
{errors.organization && ( | ||
<div className="flex items-center gap-2 px-3 py-1.5"> | ||
<ErrorIcon width={14} height={14} color={Color.red['600']} className="shrink-0" /> | ||
<span className="text-xs text-red-600">{errors.organization}</span> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
function ButtonsSection({ | ||
onCancel, | ||
confirmDisabled, | ||
disabled, | ||
}: { | ||
onCancel: () => void; | ||
confirmDisabled: boolean; | ||
disabled: boolean; | ||
}) { | ||
return ( | ||
<div className="mt-4 flex w-full items-center justify-center gap-12"> | ||
<SolidButton | ||
onClick={onCancel} | ||
color="gray" | ||
className="min-w-24 px-4 py-2" | ||
disabled={disabled} | ||
> | ||
Close | ||
</SolidButton> | ||
<SolidButton | ||
color="primary" | ||
className="min-w-24 px-4 py-2" | ||
disabled={disabled || confirmDisabled} | ||
type="submit" | ||
> | ||
Confirm | ||
</SolidButton> | ||
</div> | ||
); | ||
} | ||
|
||
const styles = { | ||
text: 'text-center text-sm text-gray-700', | ||
link: 'underline underline-offset-2 hover:opacity-80 active:opacity-70', | ||
}; | ||
|
||
function validateForm(values: GithubIdentity) { | ||
const normalizedValues = normalizeEmptyStrings(values); | ||
const parsedResult = GitHubIdentitySchema.safeParse(normalizedValues); | ||
|
||
if (!parsedResult.success) { | ||
return zodErrorToFormikErrors(parsedResult.error); | ||
} | ||
|
||
return undefined; | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.