Skip to content
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

Filter Project.lastBuild query by localBuilds: { localBuildEmailHash } so we don't see others' local builds #26

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
e7427cd
poll for git changes, and let the UI know
ndelangen Aug 2, 2023
fcd0c78
Use the CLI to get git info, in particular `creatorEmail`
tmeasday Aug 8, 2023
f7e43cd
Update OAuth Client ID
ghengeveld Aug 9, 2023
00fa44b
Add footer menu to link project screen
ghengeveld Aug 9, 2023
19a9f3d
Merge pull request #28 from chromaui/update-oauth-client-id
ghengeveld Aug 9, 2023
e58ae30
Update CHANGELOG.md [skip ci]
tmeasday Aug 9, 2023
2298885
Bump version to: 0.0.18 [skip ci]
tmeasday Aug 9, 2023
58cb746
Change API for filtering `Project.lastBuild`
tmeasday Aug 10, 2023
52804b8
Switch to passing email hashes on `localBuilds` option
tmeasday Aug 10, 2023
bf0dcfa
Merge pull request #24 from chromaui/norbert/realtime-git-info
ndelangen Aug 10, 2023
b0912aa
Update CHANGELOG.md [skip ci]
tmeasday Aug 10, 2023
3baf297
Bump version to: 0.0.19 [skip ci]
tmeasday Aug 10, 2023
d0267bf
Retrieve Git repository hash at an interval and set isOutdated:true w…
ghengeveld Aug 10, 2023
4a6e7bb
Merge branch 'main' into ghengeveld/ap-3369-add-concept-of-outdated-b…
ghengeveld Aug 10, 2023
06548e5
Update chromatic canary
tmeasday Aug 11, 2023
f902846
Upgrade canary again
tmeasday Aug 11, 2023
de710cf
Use getGitInfo from chromatic/node and set isOutdated when gitInfo ch…
ghengeveld Aug 11, 2023
1cc33f7
Derive isOutdated from uncommittedHash
ghengeveld Aug 12, 2023
3e82519
Merge pull request #29 from chromaui/add-footer-menu
ghengeveld Aug 14, 2023
7a0644b
Update CHANGELOG.md [skip ci]
tmeasday Aug 14, 2023
b1043a8
Bump version to: 0.0.20 [skip ci]
tmeasday Aug 14, 2023
9e65786
Merge branch 'main' into ghengeveld/ap-3369-add-concept-of-outdated-b…
ghengeveld Aug 15, 2023
a4c06cd
Fix state management
ghengeveld Aug 15, 2023
07216ac
Bump chromatic version
ghengeveld Aug 15, 2023
d67f31d
Avoid duplicate run test button
ghengeveld Aug 15, 2023
3829a42
Fix story data
ghengeveld Aug 15, 2023
ce985ae
UI improvements and fix stories
ghengeveld Aug 15, 2023
a718906
Upgrade to SB7.3
tmeasday Aug 16, 2023
3eba2fa
Merge pull request #32 from chromaui/Upgrade-to-SB-7.3
tmeasday Aug 16, 2023
7954ffa
Update CHANGELOG.md [skip ci]
tmeasday Aug 16, 2023
e3eb082
Bump version to: 0.0.21 [skip ci]
tmeasday Aug 16, 2023
18c125c
Merge branch 'main' into ghengeveld/ap-3369-add-concept-of-outdated-b…
ghengeveld Aug 16, 2023
062e975
Many simplifications and small improvements
ghengeveld Aug 16, 2023
168b006
Separate events for announced and started builds, and fix flicker whi…
ghengeveld Aug 16, 2023
cfea1de
Fix flicker on 'no build' screen and remove debug logging
ghengeveld Aug 16, 2023
d620d41
Bump chromatic version
ghengeveld Aug 16, 2023
f264f7e
Remove unused imports and unnecessary type definitions
ghengeveld Aug 16, 2023
4c6b7c5
Merge pull request #31 from chromaui/ghengeveld/ap-3369-add-concept-o…
ghengeveld Aug 16, 2023
1854973
Update CHANGELOG.md [skip ci]
tmeasday Aug 16, 2023
9bc131f
Bump version to: 0.0.22 [skip ci]
tmeasday Aug 16, 2023
5e2f300
Ensure we actually typecheck
tmeasday Aug 17, 2023
2e2cf8d
Fix all broken types
tmeasday Aug 17, 2023
dd82bf8
Fix type shenanigans
tmeasday Aug 17, 2023
1f2633c
Merge pull request #35 from chromaui/tom/typecheck-in-ci
tmeasday Aug 17, 2023
4424c9b
Update CHANGELOG.md [skip ci]
tmeasday Aug 17, 2023
e60289e
Bump version to: 0.0.23 [skip ci]
tmeasday Aug 17, 2023
cdee056
Merge remote-tracking branch 'origin/main' into tom/ap-3463-pass-curr…
tmeasday Aug 17, 2023
bba0628
Update Chromatic dependency
tmeasday Aug 22, 2023
d47ab47
Fix merge conflicts
tmeasday Aug 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"dependencies": {
"@storybook/csf-tools": "^7.2.0",
"@storybook/design-system": "^7.15.11",
"chromatic": "6.22.0-canary.0",
"chromatic": "6.22.0-canary.1",
"date-fns": "^2.30.0",
"pluralize": "^8.0.0",
"urql": "^4.0.3"
Expand Down
3 changes: 2 additions & 1 deletion src/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface PanelProps {
active: boolean;
}

const { GIT_BRANCH, GIT_SLUG } = process.env;
const { GIT_USER_EMAIL, GIT_BRANCH, GIT_SLUG } = process.env;

export const Panel = ({ active }: PanelProps) => {
const api = useStorybookApi();
Expand Down Expand Up @@ -79,6 +79,7 @@ export const Panel = ({ active }: PanelProps) => {
<Provider key={PANEL_ID} value={client}>
<VisualTests
projectId={projectId}
userGitEmail={GIT_USER_EMAIL}
branch={GIT_BRANCH}
slug={GIT_SLUG}
isOutdated={state.isOutdated}
Expand Down
4 changes: 2 additions & 2 deletions src/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
const documents = {
"\n query SelectProjectsQuery {\n viewer {\n accounts {\n id\n name\n avatarUrl\n projects {\n id\n name\n webUrl\n projectToken\n lastBuild {\n branch\n number\n }\n }\n }\n }\n }\n": types.SelectProjectsQueryDocument,
"\n query ProjectQuery($projectId: ID!) {\n project(id: $projectId) {\n id\n name\n webUrl\n lastBuild {\n branch\n number\n }\n }\n }\n": types.ProjectQueryDocument,
"\n query Build($hasBuildId: Boolean!, $buildId: ID!, $projectId: ID!, $branch: String!) {\n build(id: $buildId) @include(if: $hasBuildId) {\n ...BuildFields\n }\n project(id: $projectId) @skip(if: $hasBuildId) {\n name\n lastBuild(branches: [$branch]) {\n ...BuildFields\n }\n }\n }\n": types.BuildDocument,
"\n query Build(\n $hasBuildId: Boolean!\n $buildId: ID!\n $projectId: ID!\n $branch: String!\n $creatorEmail: String!\n ) {\n build(id: $buildId) @include(if: $hasBuildId) {\n ...BuildFields\n }\n project(id: $projectId) @skip(if: $hasBuildId) {\n name\n lastBuild(branches: [$branch], creatorEmail: $creatorEmail) {\n ...BuildFields\n }\n }\n }\n": types.BuildDocument,
"\n fragment BuildFields on Build {\n __typename\n id\n number\n branch\n commit\n status\n browsers {\n id\n key\n name\n }\n ... on StartedBuild {\n changeCount: testCount(results: [ADDED, CHANGED, FIXED])\n brokenCount: testCount(results: [CAPTURE_ERROR])\n startedAt\n tests {\n nodes {\n ...TestFields\n }\n }\n }\n ... on CompletedBuild {\n result\n changeCount: testCount(results: [ADDED, CHANGED, FIXED])\n brokenCount: testCount(results: [CAPTURE_ERROR])\n startedAt\n tests {\n nodes {\n ...TestFields\n }\n }\n }\n }\n": types.BuildFieldsFragmentDoc,
"\n fragment TestFields on Test {\n id\n status\n result\n webUrl\n comparisons {\n id\n result\n browser {\n id\n key\n name\n version\n }\n captureDiff {\n diffImage {\n imageUrl\n }\n }\n headCapture {\n captureImage {\n imageUrl\n }\n }\n viewport {\n id\n name\n width\n isDefault\n }\n }\n parameters {\n viewport {\n id\n name\n width\n isDefault\n }\n }\n story {\n storyId\n }\n }\n": types.TestFieldsFragmentDoc,
"\n mutation ReviewTest($input: ReviewTestInput!) {\n reviewTest(input: $input) {\n updatedTests {\n id\n status\n }\n userErrors {\n ... on UserError {\n __typename\n message\n }\n ... on BuildSupersededError {\n build {\n id\n }\n }\n ... on TestUnreviewableError {\n test {\n id\n }\n }\n }\n }\n }\n": types.ReviewTestDocument,
Expand Down Expand Up @@ -46,7 +46,7 @@ export function graphql(source: "\n query ProjectQuery($projectId: ID!) {\n
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n query Build($hasBuildId: Boolean!, $buildId: ID!, $projectId: ID!, $branch: String!) {\n build(id: $buildId) @include(if: $hasBuildId) {\n ...BuildFields\n }\n project(id: $projectId) @skip(if: $hasBuildId) {\n name\n lastBuild(branches: [$branch]) {\n ...BuildFields\n }\n }\n }\n"): (typeof documents)["\n query Build($hasBuildId: Boolean!, $buildId: ID!, $projectId: ID!, $branch: String!) {\n build(id: $buildId) @include(if: $hasBuildId) {\n ...BuildFields\n }\n project(id: $projectId) @skip(if: $hasBuildId) {\n name\n lastBuild(branches: [$branch]) {\n ...BuildFields\n }\n }\n }\n"];
export function graphql(source: "\n query Build(\n $hasBuildId: Boolean!\n $buildId: ID!\n $projectId: ID!\n $branch: String!\n $creatorEmail: String!\n ) {\n build(id: $buildId) @include(if: $hasBuildId) {\n ...BuildFields\n }\n project(id: $projectId) @skip(if: $hasBuildId) {\n name\n lastBuild(branches: [$branch], creatorEmail: $creatorEmail) {\n ...BuildFields\n }\n }\n }\n"): (typeof documents)["\n query Build(\n $hasBuildId: Boolean!\n $buildId: ID!\n $projectId: ID!\n $branch: String!\n $creatorEmail: String!\n ) {\n build(id: $buildId) @include(if: $hasBuildId) {\n ...BuildFields\n }\n project(id: $projectId) @skip(if: $hasBuildId) {\n name\n lastBuild(branches: [$branch], creatorEmail: $creatorEmail) {\n ...BuildFields\n }\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/gql/graphql.ts

Large diffs are not rendered by default.

21 changes: 3 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { Channel } from "@storybook/channels";
import { readConfig, writeConfig } from "@storybook/csf-tools";
import { exec } from "child_process";
// eslint-disable-next-line import/no-unresolved
import { run } from "chromatic/node";
import { promisify } from "util";
import { getGitInfo, GitInfo, run } from "chromatic/node";
tmeasday marked this conversation as resolved.
Show resolved Hide resolved

import {
BUILD_STARTED,
Expand Down Expand Up @@ -82,20 +80,6 @@ async function serverChannel(
return channel;
}

// TODO: use the chromatic CLI to get this info?
const execPromise = promisify(exec);
async function getGitInfo() {
const branch = (await execPromise("git rev-parse --abbrev-ref HEAD")).stdout.trim();
const commit = (await execPromise("git log -n 1 HEAD --format='%H'")).stdout.trim();
const origin = (await execPromise("git config --get remote.origin.url")).stdout.trim();

const [, slug] = origin.toLowerCase().match(/([^/:]+\/[^/]+?)(\.git)?$/) || [];
const [ownerName, repoName, ...rest] = slug ? slug.split("/") : [];
const isValidSlug = !!ownerName && !!repoName && !rest.length;

return { branch, commit, slug: isValidSlug ? slug : "" };
}

const config = {
managerEntries,
experimental_serverChannel: serverChannel,
Expand All @@ -105,11 +89,12 @@ const config = {
) => {
if (configType === "production") return env;

const { branch, commit, slug } = await getGitInfo();
const { userEmail, branch, commit, slug } = await getGitInfo();
return {
...env,
CHROMATIC_BASE_URL,
CHROMATIC_PROJECT_ID: projectId || "",
GIT_USER_EMAIL: userEmail,
GIT_BRANCH: branch,
GIT_COMMIT: commit,
GIT_SLUG: slug,
Expand Down
3 changes: 3 additions & 0 deletions src/screens/VisualTests/VisualTests.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ const meta = {
storyId: "button--primary",
projectId: "Project:id123",
updateBuildStatus: action("updateBuildStatus"),
userGitEmail: "[email protected]",
branch: "branch",
slug: "",
},
} satisfies Meta<typeof VisualTests>;

Expand Down
17 changes: 13 additions & 4 deletions src/screens/VisualTests/VisualTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ import { SnapshotComparison } from "./SnapshotComparison";
import { Warnings } from "./Warnings";

const QueryBuild = graphql(/* GraphQL */ `
query Build($hasBuildId: Boolean!, $buildId: ID!, $projectId: ID!, $branch: String!) {
query Build(
$hasBuildId: Boolean!
$buildId: ID!
$projectId: ID!
$branch: String!
$creatorEmail: String!
) {
build(id: $buildId) @include(if: $hasBuildId) {
...BuildFields
}
project(id: $projectId) @skip(if: $hasBuildId) {
name
lastBuild(branches: [$branch]) {
lastBuild(branches: [$branch], creatorEmail: $creatorEmail) {
...BuildFields
}
}
Expand Down Expand Up @@ -145,8 +151,9 @@ const MutationReviewTest = graphql(/* GraphQL */ `

interface VisualTestsProps {
projectId: string;
branch?: string;
slug?: string;
userGitEmail: string;
branch: string;
slug: string;
isOutdated?: boolean;
isRunning?: boolean;
lastDevBuildId?: string;
Expand All @@ -169,6 +176,7 @@ export const VisualTests = ({
setIsRunning,
updateBuildStatus,
projectId,
userGitEmail,
branch,
slug,
storyId,
Expand All @@ -181,6 +189,7 @@ export const VisualTests = ({
projectId,
branch: branch || "",
...(slug ? { slug } : {}),
creatorEmail: userGitEmail,
},
});

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5299,10 +5299,10 @@ chownr@^2.0.0:
resolved "https://registry.yarnpkg.com/chownr/-/chownr-2.0.0.tgz#15bfbe53d2eab4cf70f18a8cd68ebe5b3cb1dece"
integrity sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==

[email protected].0:
version "6.22.0-canary.0"
resolved "https://registry.yarnpkg.com/chromatic/-/chromatic-6.22.0-canary.0.tgz#53a5bf12ccfc2f296279883f3f0fc4fb0a3aa5e5"
integrity sha512-TI2KtEZEUOJgQjUfUaZ0U8+l734spheW74/a+csMQ+gcATxYsI3TnoB1sHrszMGeTiTx5dbxPunG3OP6ThEsVw==
[email protected].1:
version "6.22.0-canary.1"
resolved "https://registry.yarnpkg.com/chromatic/-/chromatic-6.22.0-canary.1.tgz#6c454328e8cd5f23f1dc5ec084d2055751825fab"
integrity sha512-1oeUpPek+K+xRIG86BTuCFL+nhR25N4bPEVi+KFPXNLcVzR4smD5EyGk4Q6jZoKm3RWO3H5GBIr9e53e4yYAmg==

ci-info@^3.2.0:
version "3.8.0"
Expand Down