Repository navigation
For you: one person's own page, linked by them, never by email #990
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
nambok
wants to merge
21
commits into
main
Choose a base branch
from
for-you-page
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.
+11,454
−125
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3dd8045
Every open pull request has a record and one state, read by the merge…
nambok da7e4e7
Format the pull requests route
nambok 9ef4f5d
Keep each pull request's history, change log and nightly percentiles …
nambok afe30c7
Every pull request, whoever wrote it: history backfill and health sig…
nambok 053806e
The org's pull requests in one answer: GET /api/prs/overview (#988)
nambok 43e3196
Answer the review: the gate never waits on what GitHub does not requi…
nambok 8692271
Merge the org overview's read API (#988) into the pull requests view
nambok 9f0e4ea
Merge main into the pull requests view
nambok 29dc156
For you: one person's own page, linked by them, never by email
nambok 7173abb
Merge remote-tracking branch 'origin/pull-requests-view' into for-you…
nambok fcdc9d0
Jira app 7.1.0: what a site lacks without For you's sprint, link and …
nambok 13ca67d
For you: the privacy case reads request shapes and path literals only…
nambok ff4b31f
Jira app: Forge bridge 7 and UI Kit 12, prosemirror-view held at the …
nambok 961cc69
Jira app: React 18, the one UI Kit runs on, so the link screen has a …
nambok cb2ca0d
For you: an approved plan is coded as shown
nambok 95c7933
Merge remote-tracking branch 'origin/main' into for-you-page
nambok 86de848
Jira link: a strict, size-limited request with no field it doesn't know
nambok cd381bd
Merge remote-tracking branch 'origin/main' into for-you-page
nambok 3e3b676
For you's privacy case reads the code's use-up with its expiry
nambok dfa6c64
Jira link: axum reads the body into the strict request, at most 2 KiB
nambok 9eebaff
Jira link route: the body limit by a named constant, so the route rea…
nambok 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,63 @@ | ||
| // The "Link my CoderHelm account" action, in Jira's own UI Kit: a field for | ||
| // the code from CoderHelm's For you page and one button. The resolver | ||
| // (src/link.js) does the work; this only shows what it says. | ||
|
|
||
| import React, { useState } from "react"; | ||
| import ForgeReconciler, { Box, Button, Form, FormFooter, FormSection, Label, SectionMessage, Stack, Text, Textfield, useForm } from "@forge/react"; | ||
| import { invoke, view } from "@forge/bridge"; | ||
|
|
||
| function LinkAccount() { | ||
| const { handleSubmit, register, getFieldId } = useForm(); | ||
| const [result, setResult] = useState(null); | ||
| const [busy, setBusy] = useState(false); | ||
|
|
||
| const link = async (data) => { | ||
| setBusy(true); | ||
| try { | ||
| setResult(await invoke("linkAccount", { code: data.code })); | ||
| } catch (e) { | ||
| setResult({ ok: false, message: "CoderHelm couldn't be reached. Try again in a minute." }); | ||
| } finally { | ||
| setBusy(false); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Stack space="space.200"> | ||
| <Text> | ||
| Paste the code from CoderHelm's For you page (Connect Jira). CoderHelm then knows this Jira account is yours and shows your sprint there. Only your account id is sent, never your name or email. | ||
| </Text> | ||
| {result ? ( | ||
| <SectionMessage appearance={result.ok ? "success" : "error"}> | ||
| <Text>{result.message}</Text> | ||
| </SectionMessage> | ||
| ) : null} | ||
| {result && result.ok ? ( | ||
| <Button onClick={() => view.close()}>Close</Button> | ||
| ) : ( | ||
| <Form onSubmit={handleSubmit(link)}> | ||
| <FormSection> | ||
| <Label labelFor={getFieldId("code")}>Code</Label> | ||
| <Box> | ||
| <Textfield {...register("code", { required: true })} placeholder="ABCD-EFGH-JKMN-PQRS" autoComplete="off" /> | ||
| </Box> | ||
| </FormSection> | ||
| <FormFooter> | ||
| <Button appearance="subtle" onClick={() => view.close()}> | ||
| Cancel | ||
| </Button> | ||
| <Button appearance="primary" type="submit" isDisabled={busy}> | ||
| {busy ? "Linking..." : "Link my account"} | ||
| </Button> | ||
| </FormFooter> | ||
| </Form> | ||
| )} | ||
| </Stack> | ||
| ); | ||
| } | ||
|
|
||
| ForgeReconciler.render( | ||
| <React.StrictMode> | ||
| <LinkAccount /> | ||
| </React.StrictMode>, | ||
| ); |
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,12 @@ | ||
| // The resolver behind "Link my CoderHelm account" (manifest: linkResolver). | ||
| // The work and its tests are in link.js; this file only wires it to Forge. | ||
|
|
||
| const Resolver = require("@forge/resolver").default; | ||
| const { linkAccount } = require("./link"); | ||
|
|
||
| const resolver = new Resolver(); | ||
|
|
||
| // `context.accountId` is the person who opened the action, set by Forge. | ||
| resolver.define("linkAccount", ({ payload, context }) => linkAccount(payload, context)); | ||
|
|
||
| exports.handler = resolver.getDefinitions(); |
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,110 @@ | ||
| // "Link my CoderHelm account": a person proves which Jira account is theirs. | ||
| // | ||
| // CoderHelm's For you page shows a person their own sprint, and starts work | ||
| // on a ticket with them as its owner. For that it must know which Jira | ||
| // account belongs to which CoderHelm user, and an email match can't tell: | ||
| // Atlassian lets people hide their email, and work and sign-in emails often | ||
| // differ. So the link is made by the person, from both sides at once: | ||
| // | ||
| // 1. On CoderHelm's For you page they ask for a one-time code (it is | ||
| // signed for their team and works for fifteen minutes). | ||
| // 2. Here, from any issue's "..." menu, they open "Link my CoderHelm | ||
| // account" and paste it. | ||
| // 3. This resolver sends the code with the account id Forge gives for the | ||
| // person who opened the action (`context.accountId`: Forge sets it, the | ||
| // person can't type another one) to CoderHelm, proven by the site's | ||
| // Forge secret like every event the app sends. | ||
| // | ||
| // CoderHelm then stores which CoderHelm user that Jira account is. Nothing | ||
| // about the person (no name, no email) is sent: only the account id and the | ||
| // code. Unlinking is on the For you page. | ||
|
|
||
| /** The Forge SDK, loaded when first used, so this file (and its tests) load without it. */ | ||
| function forge() { | ||
| return require("@forge/api"); | ||
| } | ||
|
|
||
| const { GATEWAY_URL } = require("./gateway"); | ||
| const { versionFields } = require("./version"); | ||
|
|
||
| /** A code as CoderHelm shows it (ABCD-EFGH-JKMN-PQRS), typed loosely. */ | ||
| function cleanCode(raw) { | ||
| const code = String(raw || "") | ||
| .toUpperCase() | ||
| .replace(/[^0-9A-Z]/g, ""); | ||
| return code.length === 16 ? code : null; | ||
| } | ||
|
|
||
| /** The body sent to CoderHelm: the team's proof, the account and the code. */ | ||
| function linkBody(config, accountId, code, getAppContext) { | ||
| return { | ||
| coderhelm: { | ||
| team_id: config.teamId, | ||
| forge_secret: config.forgeSecret, | ||
| ...versionFields(getAppContext), | ||
| }, | ||
| account_id: accountId, | ||
| code, | ||
| }; | ||
| } | ||
|
|
||
| /** What the person reads after CoderHelm answered `status` with `body`. */ | ||
| function linkResult(status, body) { | ||
| const said = body && typeof body.message === "string" ? body.message : ""; | ||
| if (status === 200) { | ||
| return { ok: true, message: said || "Linked. Your sprint shows on CoderHelm's For you page." }; | ||
| } | ||
| if (status === 410 || status === 404) { | ||
| return { ok: false, message: said || "That code has expired or was already used. Make a new one on the For you page." }; | ||
| } | ||
| if (status === 409) { | ||
| return { ok: false, message: said || "This Jira account is already linked to another CoderHelm user." }; | ||
| } | ||
| if (status === 400) { | ||
| return { ok: false, message: said || "That isn't a CoderHelm code. Copy it again from the For you page." }; | ||
| } | ||
| if (status === 403 || status === 401) { | ||
| return { ok: false, message: "CoderHelm didn't recognize this Jira site. Ask your Jira admin to check the app's settings." }; | ||
| } | ||
| return { ok: false, message: `CoderHelm couldn't link the account right now (${status}). Try again in a minute.` }; | ||
| } | ||
|
|
||
| /** | ||
| * Links the account of the person who opened the action. `deps` are the | ||
| * Forge pieces, passed in by tests. | ||
| */ | ||
| async function linkAccount(payload, context, deps = {}) { | ||
| const storage = deps.storage || forge().storage; | ||
| const fetch = deps.fetch || forge().fetch; | ||
| const accountId = String((context && context.accountId) || ""); | ||
| if (!/^[A-Za-z0-9:-]{8,128}$/.test(accountId)) { | ||
| return { ok: false, message: "Jira didn't say who you are. Open the action from an issue while signed in." }; | ||
| } | ||
| const code = cleanCode(payload && payload.code); | ||
| if (!code) { | ||
| return { ok: false, message: "That isn't a CoderHelm code. It has 16 letters and numbers, like ABCD-EFGH-JKMN-PQRS." }; | ||
| } | ||
| const config = await storage.get("coderhelm-config"); | ||
| if (!config || !config.teamId || !config.forgeSecret) { | ||
| return { ok: false, message: "This Jira site isn't connected to CoderHelm yet. Ask your Jira admin to set it up." }; | ||
| } | ||
| try { | ||
| const res = await fetch(`${GATEWAY_URL}/webhooks/jira-link`, { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify(linkBody(config, accountId, code, deps.getAppContext)), | ||
| }); | ||
| let body = null; | ||
| try { | ||
| body = await res.json(); | ||
| } catch (_) { | ||
| body = null; | ||
| } | ||
| return linkResult(res.status, body); | ||
| } catch (e) { | ||
| console.error("Link my CoderHelm account failed:", e); | ||
| return { ok: false, message: "CoderHelm couldn't be reached. Try again in a minute." }; | ||
| } | ||
| } | ||
|
|
||
| module.exports = { cleanCode, linkBody, linkResult, linkAccount }; |
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.