Skip to content
Draft
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
186 changes: 178 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"@types/validator": "^13.15.3",
"@vitejs/plugin-react": "^4.2.0",
"babel-jest": "^29.7.0",
"copy-webpack-plugin": "^11.0.0",
"esbuild-loader": "^4.3.0",
"eslint": "^9.8.0",
"eslint-config-prettier": "^10.1.8",
Expand Down Expand Up @@ -110,7 +111,6 @@
"vite-plugin-checker": "^0.10.3",
"vite-plugin-dts": "~4.5.0",
"vite-tsconfig-paths": "^5.1.4",
"copy-webpack-plugin": "^11.0.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
Expand Down Expand Up @@ -142,6 +142,7 @@
"@nestjs/jwt": "^11.0.0",
"@nestjs/platform-express": "^11.1.6",
"@nestjs/typeorm": "^11.0.0",
"@octokit/auth-app": "^8.1.1",
"@packmind/deployments": "^0.0.1",
"@react-router/fs-routes": "^7.6.3",
"@react-router/node": "^7.2.0",
Expand Down
26 changes: 24 additions & 2 deletions packages/git/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,37 @@ This will create or update the file at the specified path in the repository.

### GitHub Provider

The `GithubProvider` class implements the `IGitProvider` interface and provides functionality to interact with GitHub using a personal access token.
The `GithubProvider` class implements the `IGitProvider` interface and provides functionality to interact with GitHub using either a personal access token or GitHub App authentication.

#### Initialization

##### With Personal Access Token

```typescript
import { GithubProvider } from '@packmind/git';

// Initialize with a GitHub token
const githubProvider = new GithubProvider('your-github-token', logger);
const githubProvider = new GithubProvider(
{ type: 'token', token: 'your-github-token' },
logger
);
```

##### With GitHub App Authentication

```typescript
import { GithubProvider } from '@packmind/git';

// Initialize with GitHub App credentials
const githubProvider = new GithubProvider(
{
type: 'app',
appId: 'your-app-id',
privateKey: '-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----',
installationId: 'your-installation-id',
},
logger
);
```

#### Listing Available Repositories
Expand Down
37 changes: 30 additions & 7 deletions packages/git/src/infra/repositories/GitProviderFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,43 @@ export class GitProviderFactory implements IGitProviderFactory {
}

createGitProvider(provider: GitProvider): IGitProvider {
if (!provider.token) {
throw new Error('Git provider token not configured');
}

switch (provider.source) {
case GitProviderVendors.github:
return new GithubProvider(provider.token);
case GitProviderVendors.github: {
// Check for GitHub App authentication
if (
provider.appId &&
provider.privateKey &&
provider.installationId
) {
return new GithubProvider({
type: 'app',
appId: provider.appId,
privateKey: provider.privateKey,
installationId: provider.installationId,
});
}

// Fallback to token authentication
if (!provider.token) {
throw new Error(
'GitHub provider requires either token or GitHub App credentials (appId, privateKey, installationId)',
);
}

return new GithubProvider({ type: 'token', token: provider.token });
}

case GitProviderVendors.gitlab: {
if (!provider.token) {
throw new Error('GitLab provider token not configured');
}

case GitProviderVendors.gitlab:
return new GitlabProvider(
provider.token,
this.logger,
provider.url || undefined,
);
}

default:
throw new Error(`Unsupported git provider source: ${provider.source}`);
Expand Down
Loading