Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SmartDataLab
public
applications
renovate
Commits
2820b5ee
Commit
2820b5ee
authored
7 years ago
by
Rhys Arkins
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
feat: implement findFilePaths on gitlab (#945)
parent
33851a5a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/api/gitlab.js
+20
-4
20 additions, 4 deletions
lib/api/gitlab.js
test/api/__snapshots__/gitlab.spec.js.snap
+8
-0
8 additions, 0 deletions
test/api/__snapshots__/gitlab.spec.js.snap
test/api/gitlab.spec.js
+30
-1
30 additions, 1 deletion
test/api/gitlab.spec.js
with
58 additions
and
5 deletions
lib/api/gitlab.js
+
20
−
4
View file @
2820b5ee
...
@@ -123,10 +123,26 @@ async function setBaseBranch(branchName) {
...
@@ -123,10 +123,26 @@ async function setBaseBranch(branchName) {
// Search
// Search
// Returns an array of file paths in current repo matching the fileName
// Get full file list
async
function
findFilePaths
()
{
async
function
getFileList
(
branchName
)
{
logger
.
debug
(
"
Can't find multiple package.json files in GitLab
"
);
if
(
config
.
fileList
)
{
return
[];
return
config
.
fileList
;
}
const
res
=
await
glGot
(
`projects/
${
config
.
repoName
}
/repository/tree?ref=
${
branchName
}
&recursive=1`
);
config
.
fileList
=
res
.
body
.
filter
(
item
=>
item
.
type
===
'
blob
'
)
.
map
(
item
=>
item
.
path
)
.
sort
();
return
config
.
fileList
;
}
// Return all files in the repository matching the filename
async
function
findFilePaths
(
fileName
,
branchName
=
config
.
baseBranch
)
{
return
(
await
getFileList
(
branchName
)).
filter
(
fullFilePath
=>
fullFilePath
.
endsWith
(
fileName
)
);
}
}
// Branch
// Branch
...
...
This diff is collapsed.
Click to expand it.
test/api/__snapshots__/gitlab.spec.js.snap
+
8
−
0
View file @
2820b5ee
...
@@ -193,6 +193,14 @@ Array [
...
@@ -193,6 +193,14 @@ Array [
]
]
`;
`;
exports[`api/gitlab findFilePaths(fileName) should return the files matching the fileName 1`] = `
Array [
"package.json",
"src/app/package.json",
"src/otherapp/package.json",
]
`;
exports[`api/gitlab getBranch returns a branch 1`] = `"foo"`;
exports[`api/gitlab getBranch returns a branch 1`] = `"foo"`;
exports[`api/gitlab getBranchLastCommitTime should return a Date 1`] = `2012-09-20T08:50:22.000Z`;
exports[`api/gitlab getBranchLastCommitTime should return a Date 1`] = `2012-09-20T08:50:22.000Z`;
...
...
This diff is collapsed.
Click to expand it.
test/api/gitlab.spec.js
+
30
−
1
View file @
2820b5ee
...
@@ -191,11 +191,40 @@ describe('api/gitlab', () => {
...
@@ -191,11 +191,40 @@ describe('api/gitlab', () => {
});
});
});
});
describe
(
'
findFilePaths(fileName)
'
,
()
=>
{
describe
(
'
findFilePaths(fileName)
'
,
()
=>
{
it
(
'
should return empty array
'
,
async
()
=>
{
it
(
'
warns if truncated result
'
,
async
()
=>
{
await
initRepo
(
'
some/repo
'
,
'
token
'
);
await
initRepo
(
'
some/repo
'
,
'
token
'
);
glGot
.
mockImplementationOnce
(()
=>
({
body
:
[],
}));
const
files
=
await
gitlab
.
findFilePaths
(
'
package.json
'
);
const
files
=
await
gitlab
.
findFilePaths
(
'
package.json
'
);
expect
(
files
.
length
).
toBe
(
0
);
expect
(
files
.
length
).
toBe
(
0
);
});
});
it
(
'
caches the result
'
,
async
()
=>
{
await
initRepo
(
'
some/repo
'
,
'
token
'
);
glGot
.
mockImplementationOnce
(()
=>
({
body
:
[],
}));
let
files
=
await
gitlab
.
findFilePaths
(
'
package.json
'
);
expect
(
files
.
length
).
toBe
(
0
);
files
=
await
gitlab
.
findFilePaths
(
'
package.js
'
);
expect
(
files
.
length
).
toBe
(
0
);
});
it
(
'
should return the files matching the fileName
'
,
async
()
=>
{
await
initRepo
(
'
some/repo
'
,
'
token
'
);
glGot
.
mockImplementationOnce
(()
=>
({
body
:
[
{
type
:
'
blob
'
,
path
:
'
package.json
'
},
{
type
:
'
blob
'
,
path
:
'
some-dir/package.json.some-thing-else
'
,
},
{
type
:
'
blob
'
,
path
:
'
src/app/package.json
'
},
{
type
:
'
blob
'
,
path
:
'
src/otherapp/package.json
'
},
],
}));
const
files
=
await
gitlab
.
findFilePaths
(
'
package.json
'
);
expect
(
files
).
toMatchSnapshot
();
});
});
});
describe
(
'
branchExists(branchName)
'
,
()
=>
{
describe
(
'
branchExists(branchName)
'
,
()
=>
{
it
(
'
should return true if 200 OK
'
,
async
()
=>
{
it
(
'
should return true if 200 OK
'
,
async
()
=>
{
...
...
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