Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get entire repo comments on app install #66

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions src/lib/github/changedFilesList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export default async function getChangedFiles(context: Context): Promise<Modifie
const modifiedFiles: Array<Promise<ModifiedFile>> =
result.data.files.map(async(file) => {
const name = file.filename;
const content = await octokit.repos.getContent({owner, repo, path: name});
const content = await octokit.repos.getContents({owner, repo, path: name});
return {
name,
htmlUrl: content.data.html_url,
downloadUrl: content.data.download_url,
htmlUrl: content.html_url,
downloadUrl: content.download_url,
author
};
});
Expand Down
14 changes: 12 additions & 2 deletions src/lib/github/getFilesOnInstall.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
/**
* Gets files that have changed in the last commits
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe comment should change. I think it should be something like Get all repo files.

*/
import { Context, ModifiedFile } from "./types";
import { Context, ModifiedFile, File } from "./types";
import { getBasicRepoProps, getfileNames } from "./utils";

export default async function getFiles(context: Context): Promise<ModifiedFile[]> {
const { owner, repo } = getBasicRepoProps (context);
const sha = context.payload.head_commit.id;
const octokit = context.github;
const treeObject = await octokit.gitdata.getTree({owner, repo, sha, recursive: 5});
return treeObject.tree.map( async (obj) => {
const arrFile: File[] = treeObject.tree.map( async (obj) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arrFile type is wrong. It returns an array of Promises, so its type is rightly

const arrFile: Array<Promise<File[]>> 

To make it File[] you will have to use Promise.all and await on the returned values of treeObject.tree.map function

return getfileNames(octokit, owner, repo, obj.sha);
});
const modifiedFiles: Array<Promise<ModifiedFile>> = arrFile.map( async (objFile: File) => {
const content = await octokit.repos.getContents({owner, repo, path: objFile.name});
return {
name: objFile.name,
htmlUrl: content.html_url,
downloadUrl: content.download_url,
author: owner
};
});
return Promise.all(modifiedFiles);
}
5 changes: 2 additions & 3 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ export async function addRepoCommentsToGH(context: Context): Promise<void> {
}

export async function addCommentsToGHonInstall(context: Context): Promise<void> {
// get changed files on a git push
// get changed files on install
const changedFiles = await getFiles(context);
// get file data
const filesContent: FilesContent[] = await getFilesContent(changedFiles); // error handling
// FIXME: this doesnot work
// Just ignore it

const filesRepoIssues = filesContent.map(parseData);
// merge into a single set of FIXME and TODO issues
const repoIssues = mergeFileRepoIssues(filesRepoIssues);
Expand Down