Skip to content

Commit

Permalink
feat: Split fetch-issues.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris committed Sep 15, 2020
1 parent 5019973 commit ad2bbb0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 47 deletions.
39 changes: 39 additions & 0 deletions actions/src/fetch-issues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import fs from 'fs';
import path from 'path';
import {GitHubAPI} from './github-api';
import {Inputs, Repository, Issues, Comments} from './interfaces';

export async function fetchIssues(inps: Inputs, tmpDir: string): Promise<Repository> {
const repoName: Array<string> = inps.Repository.split('/');
const repository: Repository = {
owner: repoName[0],
name: repoName[1],
issues: <Issues>{},
comments: <Comments>{}
};

const githubAPI = new GitHubAPI(inps.GithubToken, repository.owner, repository.name);

const issues: Issues = {
data: await githubAPI.getIssues(),
fileName: 'issues.json',
location: tmpDir,
fullPath: ''
};
issues.fullPath = path.join(issues.location, issues.fileName);
fs.writeFileSync(issues.fullPath, JSON.stringify(issues.data));

const comments: Comments = {
data: await githubAPI.getComments(),
fileName: 'comments.json',
location: tmpDir,
fullPath: ''
};
comments.fullPath = path.join(comments.location, comments.fileName);
fs.writeFileSync(comments.fullPath, JSON.stringify(comments.data));

repository.issues = issues;
repository.comments = comments;

return repository;
}
23 changes: 23 additions & 0 deletions actions/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,26 @@ export interface CmdResult {
exitcode: number;
output: string;
}

export interface Repository {
owner: string;
name: string;
issues: Issues;
comments: Comments;
}

export interface Issues {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: any;
fileName: string;
location: string;
fullPath: string;
}

export interface Comments {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: any;
fileName: string;
location: string;
fullPath: string;
}
51 changes: 4 additions & 47 deletions actions/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,12 @@ import * as core from '@actions/core';
import * as io from '@actions/io';
// import * as exec from '@actions/exec';
// import * as github from '@actions/github';
import {Inputs} from './interfaces';
import {Inputs, Repository} from './interfaces';
import {showInputs, getInputs} from './get-inputs';
import {GitHubAPI} from './github-api';
import fs from 'fs';
import {fetchIssues} from './fetch-issues';
import path from 'path';
import * as artifact from '@actions/artifact';

interface Repository {
owner: string;
name: string;
}

interface Issues {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: any;
fileName: string;
location: string;
fullPath: string;
}

interface Comments {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: any;
fileName: string;
location: string;
fullPath: string;
}

export async function run(): Promise<void> {
try {
const inps: Inputs = getInputs();
Expand All @@ -48,28 +26,7 @@ export async function run(): Promise<void> {
await io.mkdirP(tmpDir);

core.startGroup('Fetch and save issues and comments');
const repoName: Array<string> = inps.Repository.split('/');
const repository: Repository = {
owner: repoName[0],
name: repoName[1]
};
const githubAPI = new GitHubAPI(inps.GithubToken, repository.owner, repository.name);
const issues: Issues = {
data: await githubAPI.getIssues(),
fileName: 'issues.json',
location: tmpDir,
fullPath: ''
};
issues.fullPath = path.join(issues.location, issues.fileName);
fs.writeFileSync(issues.fullPath, JSON.stringify(issues.data));
const comments: Comments = {
data: await githubAPI.getComments(),
fileName: 'comments.json',
location: tmpDir,
fullPath: ''
};
comments.fullPath = path.join(comments.location, comments.fileName);
fs.writeFileSync(comments.fullPath, JSON.stringify(comments.data));
const repository: Repository = await fetchIssues(inps, tmpDir);
core.endGroup();

core.startGroup('Upload training data as artifact');
Expand All @@ -79,7 +36,7 @@ export async function run(): Promise<void> {
};
const uploadResult = await artifactClient.uploadArtifact(
'training_data',
[issues.fullPath, comments.fullPath],
[repository.issues.fullPath, repository.comments.fullPath],
tmpDir,
artifactOptions
);
Expand Down

0 comments on commit ad2bbb0

Please sign in to comment.