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

Arc 968 view repos addons #2357

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
2a1a19f
display list of repos states
jkay-atlas Mar 1, 2023
76f86e2
added pagination for repo list
jkay-atlas Mar 2, 2023
8d29cfc
Merge branch 'main' into ARC-968-view-repos
joshkay10 Mar 2, 2023
80880df
removed unusd handlebar helper
jkay-atlas Mar 2, 2023
2bb2a60
Merge branch 'main' into ARC-968-view-repos
joshkay10 Mar 5, 2023
0855423
Merge branch 'main' into ARC-968-view-repos
joshkay10 Mar 7, 2023
2651b6c
Merge branch 'main' into ARC-968-view-repos
joshkay10 Mar 12, 2023
ab71260
Merge branch 'main' into ARC-968-view-repos
rachellerathbone Mar 13, 2023
c090d65
Merge branch 'main' into ARC-968-view-repos
joshkay10 Mar 14, 2023
b2d5466
minor tidies on order and view hbs
jkay-atlas Mar 14, 2023
ad10523
Merge branch 'main' into ARC-968-view-repos
Harminder84 Apr 3, 2023
c13f6c9
Updated pagination, adding filtering and searching
Harminder84 Apr 6, 2023
1988d09
Merge branch 'main' into ARC-968-view-repos
Harminder84 Apr 6, 2023
4bbec83
update message
Harminder84 Apr 6, 2023
00ad2f0
Merge branch main into ARC-968-view-repos
Harminder84 Jun 25, 2023
49b8ed7
updated UI as per specs
Harminder84 Jun 29, 2023
c985e19
Merge branch main into ARC-968-view-repos
Harminder84 Jun 29, 2023
db71b9e
Merge branch 'main' into ARC-968-view-repos
Harminder84 Jun 29, 2023
c5d4ec4
Merge branch 'main' into ARC-968-view-repos
Harminder84 Jun 29, 2023
e5001b3
Merge branch 'main' into ARC-968-view-repos
Harminder84 Jun 30, 2023
05c5d39
fix unit testing
Harminder84 Jun 30, 2023
9b0b23e
Fixed unit testing
Harminder84 Jun 30, 2023
0eae8ea
Merge branch 'main' into ARC-968-view-repos
gxueatlassian Jul 19, 2023
db69d40
resolve import conlfict
jkay-atlas Aug 17, 2023
8d09645
Merge branch 'main' into ARC-968-view-repos
joshkay10 Aug 18, 2023
519ce2c
Merge branch 'main' into ARC-968-view-repos
joshkay10 Aug 18, 2023
2d63fad
chore: addons and fixes
kamaksheeAtl Aug 20, 2023
7f23be3
chore: merge parent branch
kamaksheeAtl Aug 21, 2023
896da53
chore: add test cases for repo view
kamaksheeAtl Aug 21, 2023
659c9df
chore: add test cases for repo view
kamaksheeAtl Aug 21, 2023
fc21edf
chore: incorporate PR reviews
kamaksheeAtl Aug 21, 2023
dda0648
Merge branch 'main' into ARC-968-view-repos
bgvozdev Aug 25, 2023
87b5cce
NONE: outlined TODOs and fixed some dodgy scenarios
bgvozdev Aug 25, 2023
63854e8
NONE: fix in_progress logic
bgvozdev Aug 28, 2023
17e8ec2
ARC-968: fix navigation
bgvozdev Aug 28, 2023
a6c1ad1
ARC-968: fix layout
bgvozdev Aug 29, 2023
1e9fa08
Merge branch 'main' into ARC-968-view-repos
bgvozdev Aug 29, 2023
caedc1d
ARC-968: filter by fullName
bgvozdev Aug 29, 2023
6cc708f
ARC-968: fix tests, add placeholders for the new tests
bgvozdev Aug 29, 2023
0238634
ARC-968: add some tests
bgvozdev Aug 30, 2023
0117676
ARC-968: fix test
bgvozdev Aug 30, 2023
192e2d5
ARC-968: tests
bgvozdev Aug 30, 2023
9a70c60
Merge branch 'main' into ARC-968-view-repos
bgvozdev Aug 31, 2023
a2a08bf
ARC-968: uncomment the FF
bgvozdev Aug 31, 2023
1028517
chore: merge parent branhc
kamaksheeAtl Aug 31, 2023
1ac8da7
chore: merge parent branhc
kamaksheeAtl Aug 31, 2023
763cc1f
chore: remove finished filter item
kamaksheeAtl Aug 31, 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
1 change: 1 addition & 0 deletions src/config/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export enum BooleanFlags {
SKIP_REQUESTED_REVIEWERS = "skip-requested-reviewers",
ENABLE_SUBSCRIPTION_DEFERRED_INSTALL = "enable-subscription-deferred-install",
EARLY_EXIT_ON_VALIDATION_FAILED = "early-exit-on-validation-failed",
ENABLE_CONNECTED_REPOS_VIEW="enable-connected-repos-view",
USE_REST_API_FOR_DISCOVERY = "use-rest-api-for-discovery-again",
ENABLE_GENERIC_CONTAINERS = "enable-generic-containers",
ENABLE_GITHUB_SECURITY_IN_JIRA = "enable-github-security-in-jira",
Expand Down
1 change: 1 addition & 0 deletions src/config/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface AppInstallation extends Octokit.AppsGetInstallationResponse {
syncWarning?: string;
totalNumberOfRepos?: number;
numberOfSyncedRepos?: number;
subscriptionId?: number;
backfillSince?: Date;
failedSyncErrors?: Record<string, number>
jiraHost: string;
Expand Down
2 changes: 1 addition & 1 deletion src/models/reposyncstate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
return RepoSyncState.create(merge(values, { subscriptionId: subscription.id }), options);
}

private static async countSubscriptionRepos(subscription: Subscription, options: CountOptions = {}): Promise<number> {
static async countSubscriptionRepos(subscription: Subscription, options: CountOptions = {}): Promise<number> {
return RepoSyncState.count(merge(options, {
where: {
subscriptionId: subscription.id
Expand All @@ -188,7 +188,7 @@
}

static async findRepoByRepoIdAndJiraHost(repoId: number, jiraHost: string): Promise<RepoSyncState & Subscription | null> {
const results = await this.sequelize!.query(

Check warning on line 191 in src/models/reposyncstate.ts

View workflow job for this annotation

GitHub Actions / build

Forbidden non-null assertion
"SELECT * " +
"FROM \"Subscriptions\" s " +
"LEFT JOIN \"RepoSyncStates\" rss on s.\"id\" = rss.\"subscriptionId\" " +
Expand Down Expand Up @@ -312,7 +312,7 @@
LIMIT :limit
`;

const repositories = await this.sequelize!.query(query, {

Check warning on line 315 in src/models/reposyncstate.ts

View workflow job for this annotation

GitHub Actions / build

Forbidden non-null assertion
replacements: {
jiraHost,
subscriptionIds: subscriptionIdsArray,
Expand All @@ -327,7 +327,7 @@
}

static async findOneForRepoUrlAndRepoIdAndJiraHost(repoUrl: string, repoId: number, jiraHost: string):Promise<RepoSyncState | null> {
const results = await this.sequelize!.query(

Check warning on line 330 in src/models/reposyncstate.ts

View workflow job for this annotation

GitHub Actions / build

Forbidden non-null assertion
`SELECT rss.*
FROM "RepoSyncStates" rss
JOIN "Subscriptions" s ON rss."subscriptionId" = s."id"
Expand Down
199 changes: 199 additions & 0 deletions src/routes/jira/jira-get-connected-repos.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
import { Request, Response, NextFunction } from "express";
import { Subscription } from "~/src/models/subscription";
import { RepoSyncState } from "~/src/models/reposyncstate";
import { Op } from "sequelize";
import { JiraGetConnectedRepos } from "./jira-get-connected-repos";
jest.mock("~/src/models/subscription");
jest.mock("~/src/models/reposyncstate");

describe("JiraGetConnectedRepos", () => {
let req: Request;
let res: Response;
let next: NextFunction;
let repo;

beforeEach(async () => {
req = {
params: { subscriptionId: "111222333" },
log: { error: jest.fn() },
query: {
page: 1,
pageSize: 3,
repoName: "github-for-jira",
syncStatus: "finished"
}
} as unknown as Request;
res = {
status: jest.fn(() => res),
send: jest.fn(),
render: jest.fn().mockReturnValue({}),
locals: {
jiraHost: null,
nonce: null
}
} as unknown as Response;
next = jest.fn();
repo = {
subscriptionId: "111222333",
repoId: 1,
repoName: "github-for-jira",
repoOwner: "atlassian",
repoFullName: "atlassian/github-for-jira",
repoUrl: "github.com/atlassian/github-for-jira"
};
});
afterEach(() => {
jest.resetAllMocks();
});
it("should handle missing subscription ID", async () => {
const request = {
...req,
params: {
...req.params,
subscriptionId: null
}
} as unknown as Request;
await JiraGetConnectedRepos(request, res, next);
expect(res.status).toHaveBeenCalledWith(401);
expect(req.log.error).toHaveBeenCalledWith("Missing Subscription ID");
expect(res.status).toHaveBeenCalledTimes(1);
expect(res.send).toHaveBeenCalledWith("Missing Subscription ID");
expect(Subscription.findByPk).not.toHaveBeenCalled();
expect(next).not.toHaveBeenCalled();
});
it("should handle missing subscription", async () => {
Subscription.findByPk = jest.fn().mockResolvedValueOnce(null);
await JiraGetConnectedRepos(req, res, next);
expect(req.log.error).toHaveBeenCalledTimes(1);
expect(req.log.error).toHaveBeenCalledWith("Missing Subscription");
expect(res.status).toHaveBeenCalledTimes(1);
expect(res.status).toHaveBeenCalledWith(401);
expect(res.send).toHaveBeenCalledTimes(1);
expect(res.send).toHaveBeenCalledWith("Missing Subscription");
expect(Subscription.findByPk).toHaveBeenCalledTimes(1);
expect(Subscription.findByPk).toHaveBeenCalledWith(111222333);
expect(next).not.toHaveBeenCalled();
});
it("should handle error", async () => {
Subscription.findByPk = jest
.fn()
.mockRejectedValueOnce(new Error("something went wrong"));
await JiraGetConnectedRepos(req, res, next);
expect(res.status).not.toHaveBeenCalled();
expect(res.send).not.toHaveBeenCalled();
expect(next).toHaveBeenCalledTimes(1);
expect(next).toHaveBeenCalledWith(
new Error("Failed to render connected repos: Error: something went wrong")
);
});

it("should call RepoSyncState.countSubscriptionRepos() with the correct arguments", async () => {
const countSubscriptionRepos = jest
.spyOn(RepoSyncState, "countSubscriptionRepos")
.mockResolvedValueOnce(15);
const subscription = { id: 1 };
Subscription.findByPk = jest.fn().mockResolvedValueOnce(subscription);

await JiraGetConnectedRepos(req, res, next);

expect(countSubscriptionRepos).toHaveBeenCalledWith(subscription, {
where: {
[Op.and]: [
{
repoName: {
[Op.iLike]: "%github-for-jira%"
}
},
{
[Op.or]: [
{
branchStatus: "finished"
},
{
commitStatus: "finished"
},
{
pullStatus: "finished"
},
{
buildStatus: "finished"
},
{
deploymentStatus: "finished"
}
]
}
]
}
});
});

it("should call RepoSyncState.findAllFromSubscription() with the correct arguments", async () => {
const reposyncState = [
{
...repo,
pullStatus: "pending",
commitStatus: "complete",
branchStatus: "pending",
buildStatus: "complete",
deploymentStatus: "complete"
},
{
...repo,
pullStatus: "complete",
commitStatus: "failed",
branchStatus: "complete",
buildStatus: "failed",
deploymentStatus: "complete"
},
{
...repo,
pullStatus: "complete",
commitStatus: "complete",
branchStatus: "complete",
buildStatus: "complete",
deploymentStatus: "complete"
}
];
const findAllFromSubscription = jest
.spyOn(RepoSyncState, "findAllFromSubscription")
.mockResolvedValueOnce(Promise.resolve(reposyncState));
const subscription = { id: 1 };
Subscription.findByPk = jest.fn().mockResolvedValueOnce(subscription);

await JiraGetConnectedRepos(req, res, next);

expect(findAllFromSubscription).toHaveBeenCalledWith(subscription, {
limit: 3,
offset: 0,
where: {
[Op.and]: [
{
repoName: {
[Op.iLike]: "%github-for-jira%"
}
},
{
[Op.or]: [
{
branchStatus: "finished"
},
{
commitStatus: "finished"
},
{
pullStatus: "finished"
},
{
buildStatus: "finished"
},
{
deploymentStatus: "finished"
}
]
}
]
}
});
});
});
Loading
Loading