Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
✨ Add GitHub module
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 13, 2020
1 parent 6ad39b3 commit a0eff5a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { DnsModule } from './providers/dns/dns.module';
import { ElasticSearchModule } from './providers/elasticsearch/elasticsearch.module';
import { FirebaseModule } from './providers/firebase/firebase.module';
import { GeolocationModule } from './providers/geolocation/geolocation.module';
import { GitHubModule } from './providers/github/github.module';
import { MailModule } from './providers/mail/mail.module';
import { PrismaModule } from './providers/prisma/prisma.module';
import { S3Module } from './providers/s3/s3.module';
Expand Down Expand Up @@ -74,6 +75,7 @@ import { TasksModule } from './providers/tasks/tasks.module';
S3Module,
CloudinaryModule,
FirebaseModule,
GitHubModule,
],
providers: [
{
Expand Down
7 changes: 6 additions & 1 deletion src/config/configuration.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ export interface Configuration {
firebase: {
serviceAccountKey:
| string
| { projectId?: string; clientEmail?: string; privateKey?: string };
| { projectId?: string; clientEmail?: string; privateKey?: string };
databaseUrl: string;
};

github: {
auth: string;
userAgent?: string;
};
}
4 changes: 4 additions & 0 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ const configuration: Configuration = {
: process.env.FIREBASE_SERVICE_ACCOUNT_KEY,
databaseUrl: process.env.FIREBASE_DATABASE_URL,
},
github: {
auth: process.env.GITHUB_AUTH,
userAgent: process.env.GITHUB_USER_AGENT,
},
};

const configFunction: ConfigFactory<Configuration> = () => configuration;
Expand Down
10 changes: 10 additions & 0 deletions src/providers/github/github.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { GitHubService } from './github.service';

@Module({
imports: [ConfigModule],
providers: [GitHubService],
exports: [GitHubService],
})
export class GitHubModule {}
20 changes: 20 additions & 0 deletions src/providers/github/github.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Octokit } from '@octokit/rest';
import { Configuration } from '../../config/configuration.interface';

@Injectable()
export class GitHubService {
private logger = new Logger(GitHubService.name);
octokit: Octokit;

constructor(private configService: ConfigService) {
const config = this.configService.get<Configuration['github']>('github');
if (config.auth)
this.octokit = new Octokit({
auth: config.auth,
userAgent: config.userAgent ?? 'staart',
});
else this.logger.warn('GitHub API key not found');
}
}

0 comments on commit a0eff5a

Please sign in to comment.