Skip to content

Commit

Permalink
Merge pull request #20 from zillemarco/zillemarco-add-gitlab-pagination
Browse files Browse the repository at this point in the history
Added pagination support for the GitLab provider
  • Loading branch information
kaxada committed Jan 25, 2024
2 parents 8c4532a + c6abdcc commit 76af1d1
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 21 deletions.
74 changes: 70 additions & 4 deletions configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const fs = require("fs");
"Please input the fields below to configure your project locally"
);
const values = {
// database configuration
db_name: await input({ message: "Your database name:" }),
db_user: await input({ message: "Your database user name:" }),
db_password: await password({
Expand All @@ -22,19 +23,69 @@ const fs = require("fs");
default: "mysql",
}),

client_ID: await input({
// Github OAuth configuration
github_auth_client_ID: await input({
message: "Your personal Github OAuth App Client ID: ",
}),
client_secret: await input({
github_auth_client_secret: await input({
message: "Your personal Github OAuth App Client Secret:",
}),

// GitHub App configuration
github_app_id: await input({
message: "Your personal Github App ID: ",
}),

github_app_client_ID: await input({
message: "Your personal Github App Client ID: ",
}),

github_app_client_secret: await input({
message: "Your personal Github App Client Secret:",
}),

github_app_private_key: await input({
message: "Your personal Github App Private Key:",
}),

github_app_webhook_secret: await input({
message: "Your personal Github App Webhook Secret:",
}),

// Gitlab OAuth configuration
gitlab_client_ID: await input({
message: "Your personal GitLab OAuth App Client ID: ",
}),
gitlab_client_secret: await input({
message: "Your personal GitLab OAuth App Client Secret:",
}),
gitlab_redirect_uri: await input({
message: "Your personal GitLab OAuth APP redirection URI:",
}),

// Augur configuration
augur_client_secret: await input({
message: "Your Augur Client Secret: ",
}),
port: await input({
message: "Port that you'd like server to run on: ",
default: 4040,
}),

// email configuration
email_host: await input({
message: "Your email host:",
default: "Gmail",
}),

email_address: await input({
message: "Your email address:",
}),

email_password: await password({
message: "Your email app password:",
mask: true,
}),
};

const envFile = `
Expand All @@ -44,10 +95,25 @@ const fs = require("fs");
DB_HOST=${values.db_host}
DB_DIALECT=${values.db_dialect}
CLIENT_ID=${values.client_ID}
CLIENT_SECRET=${values.client_secret}
GITHUB_AUTH_CLIENT_ID=${values.github_auth_client_ID}
GITHUB_AUTH_CLIENT_SECRET=${values.github_auth_client_secret}
GITHUB_APP_ID=${values.github_app_id}
GITHUB_APP_CLIENT_ID=${values.github_app_client_ID}
GITHUB_APP_CLIENT_SECRET=${values.github_app_client_secret}
GITHUB_APP_WEBHOOK_SECRET=${values.github_app_webhook_secret}
GITHUB_APP_PRIVATE_KEY=${values.github_app_private_key}
GITLAB_APP_CLIENT_ID=${values.gitlab_client_ID}
GITLAB_APP_CLIENT_SECRET=${values.gitlab_client_secret}
GITLAB_APP_REDIRECT_URI=${values.gitlab_redirect_uri}
AUGUR_CLIENT_SECRET=${values.augur_client_secret}
PORT=${values.port}
EMAIL_HOST=${values.email_host}
EMAIL_ADDRESS=${values.email_address}
EMAIL_PASSWORD=${values.email_password}
`;

fs.writeFileSync(".env", envFile);
Expand Down
48 changes: 31 additions & 17 deletions providers/gitlab/APICalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,44 @@ const getUserInfo = async (access_token) => {
* @returns A json object with `repositories` and `errors`
*/
const getUserRepositories = async (access_token) => {
const repositories = [];
try {
// Authenticated user details
const { data } = await axios.get(
"https://gitlab.com/api/v4/projects?owned=true&visibility=public",
{
headers: {
Accept: "application/json",
Authorization: `Bearer ${access_token}`,
},
}
);
const requestHeaders = {
Accept: "application/json",
Authorization: `Bearer ${access_token}`,
};

let hasMorePages = true;
let pageIndex = 1;
while (hasMorePages) {
const response = await axios.get(
`https://gitlab.com/api/v4/projects?owned=true&visibility=public&per_page=100&page=${pageIndex}`,
{
headers: requestHeaders,
}
);

const { data, headers } = response;
hasMorePages = !!headers["x-next-page"];
pageIndex++;

repositories.push(
...data.map((repo) => {
return {
id: repo.id,
fullName: repo.name_with_namespace,
};
})
);
}

return {
repositories: data.map((repo) => {
return {
id: repo.id,
fullName: repo.name_with_namespace,
};
}),
repositories,
errors: [],
};
} catch (error) {
return {
repositories: null,
repositories,
errors: [error.message],
};
}
Expand Down

0 comments on commit 76af1d1

Please sign in to comment.