Skip to content

Commit

Permalink
encapsulate createIssue service
Browse files Browse the repository at this point in the history
  • Loading branch information
jcabrerizo committed Jan 23, 2024
1 parent 5b53139 commit aed7d38
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/commands/create-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from "node:fs";

import CreateIssueOpt from "./opts/create-issue-opt.js";
import {SleekCommand} from "../sleek-command.js";
import {createIssue, getRepoName, getRepoOwner, validateInputFileSchema} from "../service/create-issue-svc.js";
import {createIssue, validateInputFileSchema} from "../service/create-issue-svc.js";
import {issueData} from "../types/issue.js";

const Ajv = _Ajv as unknown as typeof _Ajv.default;
Expand Down Expand Up @@ -31,11 +31,9 @@ export default class CreateIssue extends SleekCommand {
// validateChart(helmCharName, helmChartVersion);

// create issue base in the file input
const repo = flags.repo || getRepoName();
const owner = flags.repoOwner || getRepoOwner();
const title = `Onboarding ${(data.body as issueData).sellerMarketPlaceAlias} ${(data.body as issueData).addon.name}@${(data.body as issueData).addon.version}`;
const body= `Issue body:\n\n\`\`\`yaml\n${fileContents}\`\`\`\n`;
const createIssueResponse = await createIssue(repo, owner, title, body,this, ['pending'])
const createIssueResponse = await createIssue(title, body,this, ['pending'])

this.log(`Issue created: ${createIssueResponse.body?.data.html_url}`)
}
Expand Down
9 changes: 6 additions & 3 deletions src/service/create-issue-svc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import type {OctokitResponse} from "@octokit/types/dist-types/OctokitResponse.js

const Ajv = _Ajv as unknown as typeof _Ajv.default;

export async function createIssue(repo: string, owner: string, title: string, body: string, callerCommand: SleekCommand, labels: string[] = []): Promise<svcResponse<OctokitResponse<any>>> {
export const createIssue = async (title: string, body: string, callerCommand: SleekCommand, labels: string[] = []): Promise<svcResponse<OctokitResponse<any>>> => {
return createIssueOnRepo(getRepoName(), getRepoOwner(), title, body, callerCommand, labels)
}
const createIssueOnRepo = async (repo: string, owner: string, title: string, body: string, callerCommand: SleekCommand, labels: string[]): Promise<svcResponse<OctokitResponse<any>>> => {
const octokitOptions = {
auth: process.env.GITHUB_TOKEN,
};
Expand Down Expand Up @@ -67,10 +70,10 @@ function getSchemaUrl(): string {
return 'https://raw.githubusercontent.com/elamaran11/aws-sleek-transformer/f96009d3feb4967b4d92fd57f4d1bd2cf148e1a9/src/schemas/issue-creation.schema.json'
}

export function getRepoOwner() {
function getRepoOwner() {
return 'cloudsoft-fusion';
}

export function getRepoName() {
function getRepoName() {
return 'aws-k8s-addons'
}

0 comments on commit aed7d38

Please sign in to comment.