Skip to content

Commit

Permalink
fix updates and api keys
Browse files Browse the repository at this point in the history
  • Loading branch information
bemijonathan committed May 12, 2024
1 parent 7b721c4 commit a5cf733
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 31 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ jobs:
with:
gitHubToken: ${{ secrets.GIT_HUB_TOKEN }}
openAIKey: ${{ secrets.OPENAI_API_KEY }}
# -- Jira credentials
jiraEmail: ${{ secrets.JIRA_EMAIL }}
jiraApiKey: ${{ secrets.JIRA_API_KEY }}
jiraHost: ${{ secrets.JIRA_HOST }}
# -- trello credentials
trelloPublicKey: ${{ secrets.TRELLO_PUBLIC_KEY }}
trelloPrivateKey: ${{ secrets.TRELLO_PRIVATE_KEY }}

- name: Print Output
id: output
Expand Down
23 changes: 14 additions & 9 deletions src/clients/base-client.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
import { Logger } from '../utils'
import * as core from '@actions/core'
import { TrelloClient } from './trello'
import { JiraClient } from './jira'

export class BaseClient {
static get client(): TrelloClient | JiraClient | null {
const trelloCredentials = {
trelloPublicKey: process.env.TRELLO_PUBLIC_KEY,
trelloPrivateKey: process.env.TRELLO_PRIVATE_KEY
key:
core.getInput('trelloPublicKey') || process.env.TRELLO_PUBLIC_KEY || '',
token:
core.getInput('trelloPrivateKey') ||
process.env.TRELLO_PRIVATE_KEY ||
''
}

if (this.validateCredentials(trelloCredentials)) {
return new TrelloClient()
return new TrelloClient(trelloCredentials)
}

const jiraCredentials: Record<string, unknown> = {
jiraApiKey: process.env.JIRA_API_KEY,
jiraEmail: process.env.JIRA_EMAIL,
jiraHost: process.env.JIRA_HOST
}
const jiraCredentials = {
jiraApiKey: core.getInput('jiraApiKey') || process.env.JIRA_API_KEY || '',
jiraEmail: core.getInput('jiraEmail') || process.env.JIRA_EMAIL || '',
jiraHost: core.getInput('jiraHost') || process.env.JIRA_HOST || ''
} as const

if (this.validateCredentials(jiraCredentials)) {
return new JiraClient()
return new JiraClient(jiraCredentials)
}

return null
Expand Down
25 changes: 16 additions & 9 deletions src/clients/jira.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { Version2Client } from 'jira.js'
import * as core from '@actions/core'

import { Logger } from '../utils'
import { IBaseClient } from '../types/client'

type Credentials = {
jiraEmail: string
jiraApiKey: string
jiraHost: string
}

export class JiraClient implements IBaseClient {
client: Version2Client

constructor() {
this.client = this.initializeJiraClient()
constructor(credentials: Credentials) {
this.client = this.initializeJiraClient(credentials)
}

getTicketDetails = async (tickets: string[]): Promise<string[]> => {
Expand All @@ -28,15 +33,17 @@ export class JiraClient implements IBaseClient {
return issues.filter(Boolean)
}

private initializeJiraClient = () => {
const host = core.getInput('jiraHost') || process.env.JIRA_HOST || ''
private initializeJiraClient = ({
jiraHost,
jiraEmail,
jiraApiKey
}: Credentials) => {
return new Version2Client({
host,
host: jiraHost,
authentication: {
basic: {
email: core.getInput('jiraEmail') || process.env.JIRA_EMAIL || '',
apiToken:
core.getInput('jiraApiKey') || process.env.JIRA_API_KEY || ''
email: jiraEmail,
apiToken: jiraApiKey
}
}
})
Expand Down
17 changes: 6 additions & 11 deletions src/clients/trello.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ const fetch = require('node-fetch')

const trelloBaseUrl: string = 'https://api.trello.com/1/cards'

export class TrelloClient implements IBaseClient {
config: {
key: string
token: string
}
type Credentials = {
key: string
token: string
}

constructor() {
this.config = {
key: process.env.TRELLO_PRIVATE_KEY ?? '',
token: process.env.TRELLO_PRIVATE_TOKEN ?? ''
}
}
export class TrelloClient implements IBaseClient {
constructor(private readonly config: Credentials) {}

getTicketDetails = async (tickets: string[]) => {
const issues = await Promise.all(
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { CommentHandler, getChanges, SummarizeChanges } from './steps'
import dotenv from 'dotenv'
import { Logger, Templates } from './utils.js'
import { Ai } from './ai'
import { BaseClient, GithubClient, JiraClient } from './clients'
import { BaseClient, GithubClient } from './clients'
import { mockdata } from './mockdata'

dotenv.config()

// instantiate clients
const jiraClient = new JiraClient()
const githubClient = new GithubClient()
const commentsHandler = new CommentHandler(githubClient)
const ai = new Ai()
Expand Down

0 comments on commit a5cf733

Please sign in to comment.