Skip to content

Commit

Permalink
Merge branch main into ISOC-3887-secret-scanning-webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
Harminder84 committed Aug 14, 2023
2 parents 0540ebc + 28bdf07 commit ef39f39
Show file tree
Hide file tree
Showing 28 changed files with 590 additions and 282 deletions.
2 changes: 2 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ SQS_DEPLOYMENT_QUEUE_URL=http://127.0.0.1:4566/000000000000/deployment
SQS_DEPLOYMENT_QUEUE_REGION=us-west-1
SQS_BRANCH_QUEUE_URL=http://127.0.0.1:4566/000000000000/branch
SQS_BRANCH_QUEUE_REGION=us-west-1
SQS_INCOMINGANALYTICEVENTS_QUEUE_URL=http://127.0.0.1:4566/000000000000/incominganalyticevents
SQS_INCOMINGANALYTICEVENTS_QUEUE_REGION=us-west-1
MICROS_AWS_REGION=us-west-1
GLOBAL_HASH_SECRET=testsecret

Expand Down
2 changes: 2 additions & 0 deletions .env.e2e
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ SQS_DEPLOYMENT_QUEUE_URL=http://127.0.0.1:4566/000000000000/test-deployment
SQS_DEPLOYMENT_QUEUE_REGION=us-west-1
SQS_BRANCH_QUEUE_URL=http://127.0.0.1:4566/000000000000/test-branch
SQS_BRANCH_QUEUE_REGION=us-west-1
SQS_INCOMINGANALYTICEVENTS_QUEUE_URL=http://127.0.0.1:4566/000000000000/test-incominganalyticevents
SQS_INCOMINGANALYTICEVENTS_QUEUE_REGION=us-west-1
GLOBAL_HASH_SECRET=testsecret
DEBUG=nock.*

Expand Down
2 changes: 2 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ SQS_DEPLOYMENT_QUEUE_URL=http://127.0.0.1:4566/000000000000/test-deployment
SQS_DEPLOYMENT_QUEUE_REGION=us-west-1
SQS_BRANCH_QUEUE_URL=http://127.0.0.1:4566/000000000000/test-branch
SQS_BRANCH_QUEUE_REGION=us-west-1
SQS_INCOMINGANALYTICEVENTS_QUEUE_URL=http://127.0.0.1:4566/000000000000/test-incominganalyticevents
SQS_INCOMINGANALYTICEVENTS_QUEUE_REGION=us-west-1
GLOBAL_HASH_SECRET=testsecret
DEBUG=nock.*

Expand Down
2 changes: 2 additions & 0 deletions .localstack/sqs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ awslocal sqs create-queue --queue-name backfill
awslocal sqs create-queue --queue-name push
awslocal sqs create-queue --queue-name deployment
awslocal sqs create-queue --queue-name branch
awslocal sqs create-queue --queue-name incominganalyticevents

# Test queues
awslocal sqs create-queue --queue-name test-sqs-client
awslocal sqs create-queue --queue-name test-backfill
awslocal sqs create-queue --queue-name test-push
awslocal sqs create-queue --queue-name test-deployment
awslocal sqs create-queue --queue-name test-branch
awslocal sqs create-queue --queue-name test-incominganalyticevents
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ services:
SQS_DEPLOYMENT_QUEUE_URL: http://localstack:4566/000000000000/deployment
SQS_BRANCH_QUEUE_URL: http://localstack:4566/000000000000/branch
SQS_TEST_QUEUE_URL: http://localstack:4566/000000000000/test-sqs-client
SQS_INCOMINGANALYTICEVENTS_QUEUE_URL: http://localstack:4566/000000000000/incominganalyticevents
REDISX_CACHE_HOST: redis
NODE_ENV: ${NODE_ENV:-development} # defaults to development if NODE_ENV not set

Expand Down
2 changes: 2 additions & 0 deletions spa/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import StartConnection from "./pages/StartConnection";
import ConfigSteps from "./pages/ConfigSteps";
import Connected from "./pages/Connected";
import InstallationRequested from "./pages/InstallationRequested";

import * as Sentry from "@sentry/react";
import { initSentry } from "./sentry";
Expand All @@ -32,6 +33,7 @@ const App = () => {
<Route index element={<StartConnection/>}/>
<Route path="steps" element={<ConfigSteps/>}/>
<Route path="connected" element={<Connected />}/>
<Route path="installationRequested" element={<InstallationRequested />}/>
</Route>
</SentryRoutes>
</BrowserRouter>
Expand Down
31 changes: 31 additions & 0 deletions spa/src/common/LoggedinInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Button from "@atlaskit/button";
import styled from "@emotion/styled";
import { popup } from "../utils";
import analyticsClient from "../analytics";
import OAuthManager from "../services/oauth-manager";

const LoggedInContent = styled.div`
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto;
`;

const LoggedinInfo = ({ username, logout }: { username: string; logout: () => void;}) => {
const clicked = () => {
// Opens the popup for logging out of GitHub
popup("https://github.com/logout");
// Clearing the locally stored tokens
OAuthManager.clear();
// Passed callbacks, for re-rendering/changing states
logout();
analyticsClient.sendUIEvent({ actionSubject: "switchGitHubAccount", action: "clicked" });
};

return <LoggedInContent>
<div data-testid="logged-in-as">Logged in as <b>{username}</b>.&nbsp;</div>
<Button style={{ paddingLeft: 0 }} appearance="link" onClick={clicked}>Change GitHub login</Button>
</LoggedInContent>;
};

export default LoggedinInfo;
5 changes: 3 additions & 2 deletions spa/src/common/Wrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactNode } from "react";
import styled from "@emotion/styled";
import Button from "@atlaskit/button";
import ArrowLeftIcon from "@atlaskit/icon/glyph/arrow-left";
import CrossIcon from "@atlaskit/icon/glyph/cross";
import analyticsClient from "../analytics";

const navHeight = 56;
Expand All @@ -27,7 +27,8 @@ export const Wrapper = (attr: {
}) => {
return <WrapperOutterStyled>
<Button
iconBefore={<ArrowLeftIcon label="Back to home" size="medium" />}
style={{ float: "right" }}
iconBefore={<CrossIcon label="Close" size="medium" />}
appearance="subtle"
onClick={ navigateToHomePage }
>
Expand Down
72 changes: 0 additions & 72 deletions spa/src/components/SelectDropdown/index.tsx

This file was deleted.

28 changes: 0 additions & 28 deletions spa/src/components/SelectDropdown/test.tsx

This file was deleted.

1 change: 1 addition & 0 deletions spa/src/components/Step/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const Header = styled.div`
const StepTitle = styled.div`
cursor: pointer;
font-weight: 600;
font-size: ${token("space.200")};
color: token("color.text");
margin: 0 0 ${token("space.100")};
`;
Expand Down
142 changes: 142 additions & 0 deletions spa/src/pages/ConfigSteps/OrgsContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import Button, { LoadingButton } from "@atlaskit/button";
import { GitHubInstallationType } from "../../../../../src/rest-interfaces";
import styled from "@emotion/styled";
import { token } from "@atlaskit/tokens";
import { useState } from "react";
import WarningIcon from "@atlaskit/icon/glyph/warning";
import { popup } from "../../../utils";

type OrgDivType = {
key: number;
hasError: boolean;
};

const OrgsWrapper = styled.div`
max-height: 250px;
overflow-y: auto;
padding-right: 80px;
margin-right: -80px;
`;
const OrgDiv = styled.div<OrgDivType>`
display: flex;
justify-content: space-between;
align-items: ${props => props.hasError ? "start" : "center"};
padding: ${token("space.150")} 0;
margin-bottom: ${token("space.100")};
`;
const OrgName = styled.span`
color: ${token("color.text")};
font-weight: 590;
`;
const Paragraph = styled.div`
color: ${token("color.text.subtle")};
`;
const IconWrapper = styled.div`
padding-top: ${token("space.150")};
`;
const StyledLink = styled.a`
cursor: pointer;
`;

const OrganizationsList = ({
organizations,
loaderForOrgClicked,
setLoaderForOrgClicked,
clearGitHubToken,
connectingOrg,
}: {
organizations: Array<GitHubInstallationType>;
// Passing down the states and methods from the parent component
loaderForOrgClicked: boolean;
setLoaderForOrgClicked: (args: boolean) => void;
clearGitHubToken: () => void;
connectingOrg: (org: GitHubInstallationType) => void;
}) => {
const [clickedOrg, setClickedOrg] = useState<GitHubInstallationType | undefined>(undefined);
const canConnect = (org: GitHubInstallationType) => !org.requiresSsoLogin && !org.isIPBlocked && org.isAdmin;

// TODO: Automate the login after clearing the GitHub Token
const errorMessage = (org: GitHubInstallationType) => {
if (org.requiresSsoLogin) {
// TODO: Update this to support GHE
const accessUrl = `https://github.com/organizations/${org.account.login}/settings/profile`;

return <>
<Paragraph>
Make sure you can <StyledLink onClick={() => popup(accessUrl)}>access this organization</StyledLink>.
</Paragraph>
<Paragraph>
After confirming, please <StyledLink onClick={clearGitHubToken}>reset the token</StyledLink>.
</Paragraph>
</>;
}

if (org.isIPBlocked) {
return <>
<Paragraph>
Can't connect, blocked by your IP allow list.
</Paragraph>
<Button
style={{ paddingLeft: 0 }}
appearance="link"
onClick={() => popup("https://github.com/atlassian/github-for-jira/blob/main/docs/ip-allowlist.md")}
>
Learn how to fix this error
</Button>
</>;
}

if (!org.isAdmin) {
return <>
<Paragraph>
Can't connect, you're not an organization owner.<br />Ask an owner to complete this step.
</Paragraph>
</>;
}
};

return (
<OrgsWrapper>
{
organizations.map(org =>
<OrgDiv key={org.id} hasError={!canConnect(org)}>
{
canConnect(org) ? <>
<OrgName>{org.account.login}</OrgName>
{
loaderForOrgClicked && clickedOrg?.id === org.id ?
<LoadingButton style={{width: 80}} isLoading>Loading button</LoadingButton> :
<Button
isDisabled={loaderForOrgClicked && clickedOrg?.id !== org.id}
onClick={async () => {
setLoaderForOrgClicked(true);
setClickedOrg(org);
try {
// Calling the create connection function that is passed from the parent
await connectingOrg(org);
} finally {
setLoaderForOrgClicked(false);
}
}}
>
Connect
</Button>
}
</> : <>
<div>
<OrgName>{org.account.login}</OrgName>
<div>{errorMessage(org)}</div>
</div>
<IconWrapper>
<WarningIcon label="warning" primaryColor={token("color.background.warning.bold")} size="medium" />
</IconWrapper>
</>
}
</OrgDiv>
)
}
</OrgsWrapper>
);
};

export default OrganizationsList;
Loading

0 comments on commit ef39f39

Please sign in to comment.