Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Anything Llm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
Mintplex Labs
Anything Llm
Commits
93d64642
Unverified
Commit
93d64642
authored
5 months ago
by
Timothy Carambat
Committed by
GitHub
5 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Add exception handling for special case files like `Dockerfile` and `Jenkinsfile` (#2410)
parent
5ac60204
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
collector/processSingleFile/index.js
+1
-1
1 addition, 1 deletion
collector/processSingleFile/index.js
collector/utils/files/mime.js
+20
-2
20 additions, 2 deletions
collector/utils/files/mime.js
with
21 additions
and
3 deletions
collector/processSingleFile/index.js
+
1
−
1
View file @
93d64642
...
@@ -38,7 +38,7 @@ async function processSingleFile(targetFilename, options = {}) {
...
@@ -38,7 +38,7 @@ async function processSingleFile(targetFilename, options = {}) {
};
};
const
fileExtension
=
path
.
extname
(
fullFilePath
).
toLowerCase
();
const
fileExtension
=
path
.
extname
(
fullFilePath
).
toLowerCase
();
if
(
!
fileExtension
)
{
if
(
fullFilePath
.
includes
(
"
.
"
)
&&
!
fileExtension
)
{
return
{
return
{
success
:
false
,
success
:
false
,
reason
:
`No file extension found. This file cannot be processed.`
,
reason
:
`No file extension found. This file cannot be processed.`
,
...
...
This diff is collapsed.
Click to expand it.
collector/utils/files/mime.js
+
20
−
2
View file @
93d64642
const
MimeLib
=
require
(
"
mime
"
);
const
MimeLib
=
require
(
"
mime
"
);
const
path
=
require
(
"
path
"
);
class
MimeDetector
{
class
MimeDetector
{
nonTextTypes
=
[
"
multipart
"
,
"
image
"
,
"
model
"
,
"
audio
"
,
"
video
"
];
nonTextTypes
=
[
"
multipart
"
,
"
image
"
,
"
model
"
,
"
audio
"
,
"
video
"
];
badMimes
=
[
badMimes
=
[
...
@@ -44,8 +44,26 @@ class MimeDetector {
...
@@ -44,8 +44,26 @@ class MimeDetector {
);
);
}
}
// These are file types that are not detected by the mime library and need to be processed as text files.
// You should only add file types that are not detected by the mime library, are parsable as text, and are files
// with no extension. Otherwise, their extension should be added to the overrides array.
#specialTextFileTypes
=
[
"
dockerfile
"
,
"
jenkinsfile
"
];
/**
* Returns the MIME type of the file. If the file has no extension found, it will be processed as a text file.
* @param {string} filepath
* @returns {string}
*/
getType
(
filepath
)
{
getType
(
filepath
)
{
return
this
.
lib
.
getType
(
filepath
);
const
parsedMime
=
this
.
lib
.
getType
(
filepath
);
if
(
!!
parsedMime
)
return
parsedMime
;
// If the mime could not be parsed, it could be a special file type like Dockerfile or Jenkinsfile
// which we can reliably process as text files.
const
baseName
=
path
.
basename
(
filepath
)?.
toLowerCase
();
if
(
this
.
#specialTextFileTypes
.
includes
(
baseName
))
return
"
text/plain
"
;
return
null
;
}
}
}
}
...
...
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