
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Javascript / node.js code to read a single directory from a GitHub or GitLab repository. All the files (not directories) and their contents, are returned in an array or map. Useful if you want to grab a small part of some external repository for your project.
var gitdir = require('gitdir');
...
gitdir(repositoryName, directory, options, callback);
repositoryName combines the user and the repo, and the delimiter is important!
JohnDoe/CoolRepository
JohnDoe%2FCoolRepository
e.g. to read the root directory of the Github npm repository,
gitdir("npm/npm", "", {}, function(err, data) {
// data contains an array of objects with file information
});
For GitHub, the file information is similar to what you'd get from Get Contents
e.g. https://api.github.com/repos/{repositoryName}/contents/
except:
Example for a single file npm/npm/LICENSE
(contents truncated for this example)
{
"name": "LICENSE",
"path": "LICENSE",
"sha": "0b6c2287459632e4aaf63bd7d53eb9ba054b57ea",
"size": 9742,
"url": "https://api.github.com/repos/npm/npm/contents/LICENSE?ref=latest",
"html_url": "https://github.com/npm/npm/blob/latest/LICENSE",
"git_url": "https://api.github.com/repos/npm/npm/git/blobs/0b6c2287459632e4aaf63bd7d53eb9ba054b57ea",
"download_url": "https://raw.githubusercontent.com/npm/npm/latest/LICENSE",
"type": "file",
"_links": {
"self": "https://api.github.com/repos/npm/npm/contents/LICENSE?ref=latest",
"git": "https://api.github.com/repos/npm/npm/git/blobs/0b6c2287459632e4aaf63bd7d53eb9ba054b57ea",
"html": "https://github.com/npm/npm/blob/latest/LICENSE"
},
"contents": "The npm application\nCopyright (c) npm, Inc. ..."
}
For GitLab, the information is similar to what you'd get from List repository tree
e.g. https://gitlab.com/api/v4/projects/{repositoryName}/repository/tree?private_token={options.private_token}&ref={options.branch}, with the addition of a contents and a download_url, which was used to fetch the contents.
e.g. gitlab-com%2Fwww-gitlab-com/LICENCE
, you get:
{
"id": "e186012554b42685b8e3b9bd52f3658f2d1d215c",
"name": "LICENCE",
"type": "blob",
"path": "LICENCE",
"mode": "100644",
"download_url":"https://gitlab.com/api/v4/projects/gitlab-com%2Fwww-gitlab-com/repository/files/LICENCE/raw?private_token=&ref=master",
"contents": "Copyright (c) GitLab B.V. \n"
}
Option | Default | Notes |
---|---|---|
gitlab, GitLab | false | false => GitHub |
body_key | "contents" | name of the new key holding the file contents ("body") |
blob | false | GitLab only. Get content from blob blobs/:sha instead of raw file files/:file_path |
branch | "master" | note - not tested much yet... |
deleteDownloadURL | false | delete the download URL from the data, in case in contains a private_token |
fileFilter | null | see below |
gitlab_API_root | "https://gitlab.com/api/v4" | change if you have your own GitLab server |
github_API_root | "https://api.github.com" | change if you have your own GitHub server |
keepAll | false | keep all results (including directories). Normally only files are kept. |
map | false | if true, return a map (with key = path) instead of array of file information |
private_token | "" | needed if you are fetching a private repository |
recur | false | not yet supported |
user_agent | "github.com/MorganConrad/gitdir" | required for the API call, be polite |
options.fileFilter determines which files will be included
filter(filePath, fileInfo)
returns true. e.g. If you want to use multimatchFAQs
Get files from a single directory of a GitHub repositories
The npm package gitdir receives a total of 2 weekly downloads. As such, gitdir popularity was classified as not popular.
We found that gitdir demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.