Skip to Content
🦊 GitLab Integration

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:

  1. Authorization Request: The user is redirected to GitLab to authorize the Sitepins application.
  2. Callback Handling: GitLab redirects back to /gitlab-installed with an authorization code.
  3. Token Exchange: The server exchanges the code for an access token via the /api/auth/gitlab route.
  4. Provider Storage: The access_token and refresh_token are stored in the database via the createProvider action.

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/tree to 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/project becomes namespace%2Fproject).
  • Private Tokens: Supports both OAuth tokens and Personal Access Tokens for authentication.
Last updated on