这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const ignore = require("ignore");
* @property {string} [accessToken] - GitLab access token for authentication (optional).
* @property {string[]} [ignorePaths] - Array of paths to ignore when loading (optional).
* @property {boolean} [fetchIssues] - Should issues be fetched (optional).
* @property {boolean} [fetchWikis] - Should wiki be fetched (optional).
*/

/**
Expand Down Expand Up @@ -36,6 +37,7 @@ class GitLabRepoLoader {
this.ignorePaths = args?.ignorePaths || [];
this.ignoreFilter = ignore().add(this.ignorePaths);
this.withIssues = args?.fetchIssues || false;
this.withWikis = args?.fetchWikis || false;

this.projectId = null;
this.apiBase = "https://gitlab.com";
Expand Down Expand Up @@ -156,6 +158,21 @@ class GitLabRepoLoader {
);
}

if (this.withWikis) {
console.log(`[Gitlab Loader]: Fetching wiki.`);
const wiki = await this.fetchWiki();
console.log(`[Gitlab Loader]: Fetched ${wiki.length} wiki pages.`);
docs.push(
...wiki.map((wiki) => ({
wiki,
metadata: {
source: `wiki-${this.repo}-${wiki.slug}`,
url: `${this.repo}/-/wikis/${wiki.slug}`,
},
}))
);
}

return docs;
}

Expand Down Expand Up @@ -278,6 +295,23 @@ ${body}`
return issues;
}

/**
* Fetches all wiki pages from the repository.
* @returns {Promise<WikiPage[]>} An array of wiki page objects.
*/
async fetchWiki() {
const wikiRequestData = {
endpoint: `/api/v4/projects/${this.projectId}/wikis`,
queryParams: {
with_content: "1",
},
};

const wikiPages = await this.fetchNextPage(wikiRequestData);
console.log(`Total wiki pages fetched: ${wikiPages.length}`);
return wikiPages;
}

/**
* Fetches the content of a single file from the repository.
* @param {string} sourceFilePath - The path to the file in the repository.
Expand Down
12 changes: 9 additions & 3 deletions collector/utils/extensions/RepoLoader/GitlabRepo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require("fs");
const path = require("path");
const { default: slugify } = require("slugify");
const { v4 } = require("uuid");
const { writeToServerDocuments } = require("../../../files");
const { sanitizeFileName, writeToServerDocuments } = require("../../../files");
const { tokenizeString } = require("../../../tokenizer");

/**
Expand Down Expand Up @@ -50,7 +50,8 @@ async function loadGitlabRepo(args, response) {
fs.mkdirSync(outFolderPath, { recursive: true });

for (const doc of docs) {
if (!doc.metadata || (!doc.pageContent && !doc.issue)) continue;
if (!doc.metadata || (!doc.pageContent && !doc.issue && !doc.wiki))
continue;
let pageContent = null;

const data = {
Expand All @@ -77,6 +78,11 @@ async function loadGitlabRepo(args, response) {
data.title = `Issue ${doc.issue.iid}: ${doc.issue.title}`;
data.docAuthor = doc.issue.author.username;
data.description = doc.issue.description;
} else if (doc.wiki) {
pageContent = doc.wiki.content;
data.title = doc.wiki.title;
data.docAuthor = repo.author;
data.description = doc.wiki.format === "markdown" ? "GitLab Wiki Page (Markdown)" : "GitLab Wiki Page";
} else {
continue;
}
Expand All @@ -91,7 +97,7 @@ async function loadGitlabRepo(args, response) {

writeToServerDocuments(
data,
`${slugify(doc.metadata.source)}-${data.id}`,
sanitizeFileName(`${slugify(doc.metadata.source)}-${data.id}`),
outFolderPath
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default function GitlabOptions() {
branch: form.get("branch"),
ignorePaths: ignores,
fetchIssues: form.get("fetchIssues"),
fetchWikis: form.get("fetchWikis"),
});

if (!!error) {
Expand Down Expand Up @@ -120,13 +121,13 @@ export default function GitlabOptions() {
<div className="flex flex-col pr-10">
<div className="flex flex-col gap-y-1 mb-4">
<label className="text-white font-bold text-sm flex gap-x-2 items-center">
<p className="font-bold text-white">Settings</p>{" "}
<p className="font-bold text-white">Settings</p>
</label>
<p className="text-xs font-normal text-white/50">
{t("connectors.gitlab.token_description")}
<p className="text-xs font-normal text-white">
{t("connectors.gitlab.token_description")}
</p>
</div>
<div className="flex items-center gap-x-2">
<div className="flex items-center gap-x-2 mb-3">
<label className="relative inline-flex cursor-pointer items-center">
<input
type="checkbox"
Expand All @@ -140,6 +141,20 @@ export default function GitlabOptions() {
</span>
</label>
</div>
<div className="flex items-center gap-x-2">
<label className="relative inline-flex cursor-pointer items-center">
<input
type="checkbox"
name="fetchWikis"
value={true}
className="peer sr-only"
/>
<div className="peer-disabled:opacity-50 pointer-events-none peer h-6 w-11 rounded-full bg-[#CFCFD0] after:absolute after:left-[2px] after:top-[2px] after:h-5 after:w-5 after:rounded-full after:shadow-xl after:border-none after:bg-white after:box-shadow-md after:transition-all after:content-[''] peer-checked:bg-[#32D583] peer-checked:after:translate-x-full peer-checked:after:border-white peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-transparent"></div>
<span className="ml-3 text-sm font-medium text-white">
Fetch Wikis as Documents
</span>
</label>
</div>
</div>
<GitLabBranchSelection
repo={settings.repo}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/models/dataConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const DataConnector = {
branch,
ignorePaths = [],
fetchIssues = false,
fetchWikis = false,
}) {
return await fetch(`${API_BASE}/ext/gitlab/repo`, {
method: "POST",
Expand All @@ -80,6 +81,7 @@ const DataConnector = {
branch,
ignorePaths,
fetchIssues,
fetchWikis,
}),
})
.then((res) => res.json())
Expand Down