Skip to content

Commit

Permalink
Merge 0d06915 into 1e865d2
Browse files Browse the repository at this point in the history
  • Loading branch information
dunaevsky committed Dec 24, 2018
2 parents 1e865d2 + 0d06915 commit bc47cf7
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions lib/tests-from-pull-request.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
const fs = require('fs')
const readline = require('readline')
module.exports = getTestsFromPR;

module.exports = getTestsFromPR

function getTestsFromPR (context) {
function getTestsFromPR(context) {
return Promise.resolve()
.then(() => ['Hi Or'])
// .then(() => _getTestsFromPR(context))
.then(() => _getTestsFromPR(context));
}

function _getTestsFromPR (context) {
const pull = context.issue()
const {repos, pullRequests} = context.github
// todo: code to get file contect
let newTestLines = []
let PRfiles
function _getTestsFromPR(context) {
let PRfiles;
const pull = context.issue();
const {pullRequests} = context.github;

return pullRequests.getFiles(pull)
.then((res) => res.data)
.then((files) => PRfiles = files)
.then(() => console.log('FILES FROM PR:\n', PRfiles))
.then(() => PRfiles.map((file) => file.patch))
.then((patches) => patches.join('\n'))
.then(_getTestNamesFromPatch);
}


// let line = ''
// if (line.startsWith('+')) {
// line = line.slice(1).trim() // remove the + and spaces
// if (line.trim().startsWith('it(')) {
// newTestLines.push(line)
// }
// }
function _getTestNamesFromPatch(patch) {
let newTestLines = [];
const parsedPatch = patch.split('\n');
parsedPatch.forEach((line) => {
if (line.startsWith('+')) {
line = line.slice(1).trim(); // remove the + and spaces
if (line.trim().startsWith('it(')) {
const _testRegex = new RegExp('(?<=\\(\').+?(?=\'\\))', 'g');
const _testText = line.match(_testRegex)[0];
const resultLine = ['it', _testText].join(' ');
newTestLines.push(resultLine);
}
}
});
return newTestLines;

// return newTestLines
}

0 comments on commit bc47cf7

Please sign in to comment.