Skip to content

Commit 41493f9

Browse files
authored
feat: added support for adding teams as owner (#5)
* WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * added support for codeowners team * minor modifications in pull_request.json * added tests for getTeamOrIndividual * added tests for new Classes in CodeOwner module * renaming of getTeamOrindividual implemented * fixed the tests for utils * added tests for evaluate & statementStringToObj * added mock for context imported from github * fixed tests for and() & or() removed tests CodeOwnerRuleStatement#constructor() * updated dist/ * fixed the mocks * fix: fixed the failure when organization is not present * added test for use case when organization is not present in the context
1 parent 3fffa59 commit 41493f9

File tree

12 files changed

+35706
-132
lines changed

12 files changed

+35706
-132
lines changed

__mocks__/@actions/github.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
exports.context = {
2+
payload: {
3+
organization: {
4+
login: "sample_owner",
5+
},
6+
},
7+
repo: {
8+
owner: "sample_owner",
9+
repo: "sample_repo",
10+
},
11+
};

__tests__/lib/CodeOwner.test.js

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
const { Individual, Team } = require("../../src/lib/CodeOwner");
2+
3+
describe("Individual#CodeOwner", () => {
4+
describe("isCodeOwnerApprover()", () => {
5+
it("should return true if the userId is part of approvers", () => {
6+
const individual = new Individual({
7+
login: "sample_user",
8+
id: 123,
9+
});
10+
11+
expect(
12+
individual.isCodeOwnerApprover([
13+
"sample_user",
14+
"sample_user2",
15+
"sample_user3",
16+
])
17+
).toBe(true);
18+
});
19+
20+
it("should return false if userId is not part approvers list", () => {
21+
const individual = new Individual({
22+
login: "sample_user",
23+
id: 123,
24+
});
25+
26+
expect(
27+
individual.isCodeOwnerApprover(["sample_user2", "sample_user3"])
28+
).toBe(false);
29+
});
30+
31+
it("should return false if approvers list is empty", () => {
32+
const individual = new Individual({
33+
login: "sample_user",
34+
id: 123,
35+
});
36+
37+
expect(individual.isCodeOwnerApprover([])).toBe(false);
38+
});
39+
});
40+
});
41+
42+
describe("Team#CodeOwner", () => {
43+
describe("constructor()", () => {
44+
it("should assign members as Individuals from members attributes", () => {
45+
const team = new Team(
46+
{
47+
slug: "sample_team",
48+
id: 123,
49+
},
50+
[
51+
{ login: "sampleUser1", id: 789 },
52+
{ login: "sampleUser2", id: 456 },
53+
{ login: "sampleUser3", id: 124 },
54+
]
55+
);
56+
expect(team.members[0]).toBeInstanceOf(Individual);
57+
expect(team.members[1]).toBeInstanceOf(Individual);
58+
});
59+
});
60+
describe("isCodeOwnerApprover", () => {
61+
it("should return true if approvers contains at least 1 member of team", () => {
62+
const team = new Team(
63+
{
64+
slug: "sample_team",
65+
id: 123,
66+
},
67+
[
68+
{ login: "sampleUser1", id: 789 },
69+
{ login: "sampleUser2", id: 456 },
70+
{ login: "sampleUser3", id: 124 },
71+
]
72+
);
73+
expect(
74+
team.isCodeOwnerApprover(["sampleUser2", "sampleUser4", "sampleUser5"])
75+
).toBe(true);
76+
});
77+
78+
it("should return true if approvers contains more than 1 member of team", () => {
79+
const team = new Team(
80+
{
81+
slug: "sample_team",
82+
id: 123,
83+
},
84+
[
85+
{ login: "sampleUser1", id: 789 },
86+
{ login: "sampleUser2", id: 456 },
87+
{ login: "sampleUser3", id: 124 },
88+
]
89+
);
90+
expect(
91+
team.isCodeOwnerApprover(["sampleUser2", "sampleUser3", "sampleUser5"])
92+
).toBe(true);
93+
});
94+
95+
it("should return false if approvers doesn't contain any member of the team", () => {
96+
const team = new Team(
97+
{
98+
slug: "sample_team",
99+
id: 123,
100+
},
101+
[
102+
{ login: "sampleUser1", id: 789 },
103+
{ login: "sampleUser2", id: 456 },
104+
{ login: "sampleUser3", id: 124 },
105+
]
106+
);
107+
expect(
108+
team.isCodeOwnerApprover(["sampleUser4", "sampleUser5", "sampleUser6"])
109+
).toBe(false);
110+
});
111+
112+
it("should return false if approvers list is empty", () => {
113+
const team = new Team(
114+
{
115+
slug: "sample_team",
116+
id: 123,
117+
},
118+
[
119+
{ login: "sampleUser1", id: 789 },
120+
{ login: "sampleUser2", id: 456 },
121+
{ login: "sampleUser3", id: 124 },
122+
]
123+
);
124+
expect(team.isCodeOwnerApprover([])).toBe(false);
125+
});
126+
127+
it("should return false if no members in the team", () => {
128+
const team = new Team(
129+
{
130+
slug: "sample_team",
131+
id: 123,
132+
},
133+
[]
134+
);
135+
expect(
136+
team.isCodeOwnerApprover(["sampleUser4", "sampleUser5", "sampleUser6"])
137+
).toBe(false);
138+
});
139+
});
140+
});

0 commit comments

Comments
 (0)