GitLab Integration
Sitepins provides full support for GitLab, allowing users to manage their repositories directly through the GitLab REST API.
Authentication Flow
The application uses GitLab OAuth for authentication. The process is handled via the following steps:
- Authorization Request: The user is redirected to GitLab to authorize the Sitepins application.
- Callback Handling: GitLab redirects back to
/gitlab-installedwith an authorization code. - Token Exchange: The server exchanges the code for an access token via the
/api/auth/gitlabroute. - Provider Storage: The
access_tokenandrefresh_tokenare stored in the database via thecreateProvideraction.
GitLab API Integration
Sitepins interacts with GitLab using RTK Query and a custom base query that handles authentication and project path encoding.
// src/redux/features/gitlab/gitlab-api.ts
const GITLAB_API_BASE_URL = "https://gitlab.com/api/v4";
const gitlabBaseQuery = async ({ endpoint, method = "GET", body, params, token }) => {
// ... handles Bearer token authentication
};
export const gitlabApi = createApi({
reducerPath: "gitlabApi",
baseQuery: gitlabBaseQuery,
endpoints: (builder) => ({
getProjects: builder.query({ /* ... */ }),
getRepositoryTree: builder.query({ /* ... */ }),
}),
});Git Operations
Similar to GitHub, Sitepins implements a full Git workflow for GitLab:
- Tree Retrieval: Uses
/projects/:id/repository/treeto fetch the file structure. - Content Operations: Reads and writes file content using the repository files API.
- Commit Management: Creates commits with multiple file actions in a single request.
GitLab Specifics
- Project Encoding: GitLab requires project paths to be URL-encoded (e.g.,
namespace/projectbecomesnamespace%2Fproject). - Private Tokens: Supports both OAuth tokens and Personal Access Tokens for authentication.
Last updated on