Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
Renovate Bot
renovate
Commits
538522d0
Commit
538522d0
authored
4 years ago
by
Rhys Arkins
Browse files
Options
Downloads
Patches
Plain Diff
refactor: codeOwners use readLocalFile
The current branch should be drived off the targetBranch anyway
parent
74c5a162
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/workers/pr/code-owners.spec.ts
+11
-9
11 additions, 9 deletions
lib/workers/pr/code-owners.spec.ts
lib/workers/pr/code-owners.ts
+5
-5
5 additions, 5 deletions
lib/workers/pr/code-owners.ts
with
16 additions
and
14 deletions
lib/workers/pr/code-owners.spec.ts
+
11
−
9
View file @
538522d0
import
{
mock
}
from
'
jest-mock-extended
'
;
import
{
mock
}
from
'
jest-mock-extended
'
;
import
{
git
,
platform
}
from
'
../../../test/util
'
;
import
{
fs
,
platform
}
from
'
../../../test/util
'
;
import
{
Pr
}
from
'
../../platform
'
;
import
{
Pr
}
from
'
../../platform
'
;
import
{
codeOwnersForPr
}
from
'
./code-owners
'
;
import
{
codeOwnersForPr
}
from
'
./code-owners
'
;
jest
.
mock
(
'
../../util/
git
'
);
jest
.
mock
(
'
../../util/
fs
'
);
describe
(
'
workers/pr/code-owners
'
,
()
=>
{
describe
(
'
workers/pr/code-owners
'
,
()
=>
{
describe
(
'
codeOwnersForPr
'
,
()
=>
{
describe
(
'
codeOwnersForPr
'
,
()
=>
{
...
@@ -13,13 +13,13 @@ describe('workers/pr/code-owners', () => {
...
@@ -13,13 +13,13 @@ describe('workers/pr/code-owners', () => {
pr
=
mock
<
Pr
>
();
pr
=
mock
<
Pr
>
();
});
});
it
(
'
returns global code owner
'
,
async
()
=>
{
it
(
'
returns global code owner
'
,
async
()
=>
{
git
.
get
File
.
mockResolvedValueOnce
([
'
* @jimmy
'
].
join
(
'
\n
'
));
fs
.
readLocal
File
.
mockResolvedValueOnce
([
'
* @jimmy
'
].
join
(
'
\n
'
));
platform
.
getPrFiles
.
mockResolvedValueOnce
([
'
README.md
'
]);
platform
.
getPrFiles
.
mockResolvedValueOnce
([
'
README.md
'
]);
const
codeOwners
=
await
codeOwnersForPr
(
pr
);
const
codeOwners
=
await
codeOwnersForPr
(
pr
);
expect
(
codeOwners
).
toEqual
([
'
@jimmy
'
]);
expect
(
codeOwners
).
toEqual
([
'
@jimmy
'
]);
});
});
it
(
'
returns more specific code owners
'
,
async
()
=>
{
it
(
'
returns more specific code owners
'
,
async
()
=>
{
git
.
get
File
.
mockResolvedValueOnce
(
fs
.
readLocal
File
.
mockResolvedValueOnce
(
[
'
* @jimmy
'
,
'
package.json @john @maria
'
].
join
(
'
\n
'
)
[
'
* @jimmy
'
,
'
package.json @john @maria
'
].
join
(
'
\n
'
)
);
);
platform
.
getPrFiles
.
mockResolvedValueOnce
([
'
package.json
'
]);
platform
.
getPrFiles
.
mockResolvedValueOnce
([
'
package.json
'
]);
...
@@ -27,7 +27,7 @@ describe('workers/pr/code-owners', () => {
...
@@ -27,7 +27,7 @@ describe('workers/pr/code-owners', () => {
expect
(
codeOwners
).
toEqual
([
'
@john
'
,
'
@maria
'
]);
expect
(
codeOwners
).
toEqual
([
'
@john
'
,
'
@maria
'
]);
});
});
it
(
'
ignores comments and leading/trailing whitespace
'
,
async
()
=>
{
it
(
'
ignores comments and leading/trailing whitespace
'
,
async
()
=>
{
git
.
get
File
.
mockResolvedValueOnce
(
fs
.
readLocal
File
.
mockResolvedValueOnce
(
[
[
'
# comment line
'
,
'
# comment line
'
,
'
\t
'
,
'
\t
'
,
...
@@ -41,19 +41,21 @@ describe('workers/pr/code-owners', () => {
...
@@ -41,19 +41,21 @@ describe('workers/pr/code-owners', () => {
expect
(
codeOwners
).
toEqual
([
'
@john
'
,
'
@maria
'
]);
expect
(
codeOwners
).
toEqual
([
'
@john
'
,
'
@maria
'
]);
});
});
it
(
'
returns empty array when no code owners set
'
,
async
()
=>
{
it
(
'
returns empty array when no code owners set
'
,
async
()
=>
{
git
.
get
File
.
mockResolvedValueOnce
(
null
);
fs
.
readLocal
File
.
mockResolvedValueOnce
(
null
);
platform
.
getPrFiles
.
mockResolvedValueOnce
([
'
package.json
'
]);
platform
.
getPrFiles
.
mockResolvedValueOnce
([
'
package.json
'
]);
const
codeOwners
=
await
codeOwnersForPr
(
pr
);
const
codeOwners
=
await
codeOwnersForPr
(
pr
);
expect
(
codeOwners
).
toEqual
([]);
expect
(
codeOwners
).
toEqual
([]);
});
});
it
(
'
returns empty array when no code owners match
'
,
async
()
=>
{
it
(
'
returns empty array when no code owners match
'
,
async
()
=>
{
git
.
getFile
.
mockResolvedValueOnce
([
'
package-lock.json @mike
'
].
join
(
'
\n
'
));
fs
.
readLocalFile
.
mockResolvedValueOnce
(
[
'
package-lock.json @mike
'
].
join
(
'
\n
'
)
);
platform
.
getPrFiles
.
mockResolvedValueOnce
([
'
yarn.lock
'
]);
platform
.
getPrFiles
.
mockResolvedValueOnce
([
'
yarn.lock
'
]);
const
codeOwners
=
await
codeOwnersForPr
(
pr
);
const
codeOwners
=
await
codeOwnersForPr
(
pr
);
expect
(
codeOwners
).
toEqual
([]);
expect
(
codeOwners
).
toEqual
([]);
});
});
it
(
'
returns empty array when error occurs
'
,
async
()
=>
{
it
(
'
returns empty array when error occurs
'
,
async
()
=>
{
git
.
get
File
.
mockImplementationOnce
((
_
,
__
)
=>
{
fs
.
readLocal
File
.
mockImplementationOnce
((
_
,
__
)
=>
{
throw
new
Error
();
throw
new
Error
();
});
});
const
codeOwners
=
await
codeOwnersForPr
(
pr
);
const
codeOwners
=
await
codeOwnersForPr
(
pr
);
...
@@ -67,7 +69,7 @@ describe('workers/pr/code-owners', () => {
...
@@ -67,7 +69,7 @@ describe('workers/pr/code-owners', () => {
];
];
codeOwnerFilePaths
.
forEach
((
codeOwnerFilePath
)
=>
{
codeOwnerFilePaths
.
forEach
((
codeOwnerFilePath
)
=>
{
it
(
`detects code owner file at '
${
codeOwnerFilePath
}
'`
,
async
()
=>
{
it
(
`detects code owner file at '
${
codeOwnerFilePath
}
'`
,
async
()
=>
{
git
.
get
File
.
mockImplementation
((
path
,
_
)
=>
{
fs
.
readLocal
File
.
mockImplementation
((
path
,
_
)
=>
{
if
(
path
===
codeOwnerFilePath
)
{
if
(
path
===
codeOwnerFilePath
)
{
return
Promise
.
resolve
([
'
* @mike
'
].
join
(
'
\n
'
));
return
Promise
.
resolve
([
'
* @mike
'
].
join
(
'
\n
'
));
}
}
...
...
This diff is collapsed.
Click to expand it.
lib/workers/pr/code-owners.ts
+
5
−
5
View file @
538522d0
import
ignore
from
'
ignore
'
;
import
ignore
from
'
ignore
'
;
import
{
logger
}
from
'
../../logger
'
;
import
{
logger
}
from
'
../../logger
'
;
import
{
Pr
,
platform
}
from
'
../../platform
'
;
import
{
Pr
,
platform
}
from
'
../../platform
'
;
import
{
get
File
}
from
'
../../util/
git
'
;
import
{
readLocal
File
}
from
'
../../util/
fs
'
;
export
async
function
codeOwnersForPr
(
pr
:
Pr
):
Promise
<
string
[]
>
{
export
async
function
codeOwnersForPr
(
pr
:
Pr
):
Promise
<
string
[]
>
{
try
{
try
{
const
codeOwnersFile
=
const
codeOwnersFile
=
(
await
get
File
(
'
CODEOWNERS
'
,
pr
.
targetBranch
))
||
(
await
readLocal
File
(
'
CODEOWNERS
'
,
'
utf8
'
))
||
(
await
get
File
(
'
.github/CODEOWNERS
'
,
pr
.
targetBranch
))
||
(
await
readLocal
File
(
'
.github/CODEOWNERS
'
,
'
utf8
'
))
||
(
await
get
File
(
'
.gitlab/CODEOWNERS
'
,
pr
.
targetBranch
))
||
(
await
readLocal
File
(
'
.gitlab/CODEOWNERS
'
,
'
utf8
'
))
||
(
await
get
File
(
'
docs/CODEOWNERS
'
,
pr
.
targetBranch
));
(
await
readLocal
File
(
'
docs/CODEOWNERS
'
,
'
utf8
'
));
if
(
!
codeOwnersFile
)
{
if
(
!
codeOwnersFile
)
{
return
[];
return
[];
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment