async function getFileAndDiff()

in pull-request-evaluator/lib/github-client/pr.js [103:141]


async function getFileAndDiff(owner, repo, file, basesha) {
    let thisFile = {
        fileName: null,
        fileContent: null,
        newContent: null,
        fileDiff: null,
        diffSummary: null,
        changeStatus: null
    };

    thisFile.fileName = file.filename;

    try {
        const contents = await githubClient.repos.getContent({
            owner: owner,
            repo: repo,
            path: file.filename,
            ref: basesha
        });
        if (contents.data != null) {
            if (!Array.isArray(contents.data)) {
                if (contents.data.type === 'file' && contents.data.content != null) {
                    thisFile.fileContent = Buffer.from(contents.data.content, 'base64').toString();
                }
            }
        }
    } catch (err) {
        /* Probably a 404, brand new file */
        console.log(err);
        thisFile.fileContent = "";
    }

    if (file.patch != null) {
        thisFile.fileDiff = file.patch;
    }

    return thisFile;

}