Skip to content

Commit

Permalink
✨ Fetch PRs from github commits
Browse files Browse the repository at this point in the history
  • Loading branch information
mickaelalibert committed Sep 15, 2023
1 parent 0fc2d4b commit 68be686
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
9 changes: 7 additions & 2 deletions common/services/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ async function getSecondToLastRelease(repoOwner, repoName) {
return tags[1];
}

async function getPullRequestsForCommit(repoOwner, repoName, commitSha) {
logger.info(repoOwner, repoName, commitSha);
return [];
}

async function _getTags(repoOwner, repoName) {
const { repos } = _createOctokit();
const { data } = await repos.listTags({
Expand Down Expand Up @@ -328,7 +333,7 @@ module.exports = {
async getMergedPullRequestsSortedByDescendingDate(repoOwner, repoName, branchName) {
return _getMergedPullRequestsSortedByDescendingDate(repoOwner, repoName, branchName);
},

getPullRequestsForCommit,
async getDefaultBranch(repoOwner, repoName) {
return _getDefaultBranch(repoOwner, repoName);
},
Expand Down Expand Up @@ -363,7 +368,7 @@ module.exports = {
const commits = await _getCommitsWhereConfigFileHasChangedBetweenDate(repoOwner, repoName, latestReleaseDate, now);
const hasConfigFileChanged = commits.length > 0;
const latestTag = await _getLatestReleaseTagName(repoOwner, repoName);
return { hasConfigFileChanged, latestTag };
return { hasConfigFileChanged, latestTag, commits };
},

async hasConfigFileChangedInLatestRelease(repoOwner = settings.github.owner, repoName = settings.github.repository) {
Expand Down
28 changes: 25 additions & 3 deletions test/unit/build/services/github_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ describe('github-test', function () {
clock.restore();
});

context('should return true when config file has been changed', function () {
context('should return true when config file has been changed and return concerned commits', function () {
it('should call Github "commits list" API', async function () {
// given
nock('https://api.github.com')
Expand All @@ -345,7 +345,15 @@ describe('github-test', function () {
// when
const response = await githubService.hasConfigFileChangedSinceLatestRelease(repoOwner, repoName);
// then
expect(response).to.be.deep.equal({ hasConfigFileChanged: true, latestTag: 'v6.6.6' });
expect(response).to.be.deep.equal({
hasConfigFileChanged: true,
latestTag: 'v6.6.6',
commits: [
{
sha: '5ec2f42',
},
],
});
});
});

Expand All @@ -371,11 +379,25 @@ describe('github-test', function () {
// when
const response = await githubService.hasConfigFileChangedSinceLatestRelease(repoOwner, repoName);
// then
expect(response).to.be.deep.equal({ hasConfigFileChanged: false, latestTag: 'v6.6.6' });
expect(response).to.be.deep.equal({ hasConfigFileChanged: false, latestTag: 'v6.6.6', commits: [] });
});
});
});

describe('#getPullRequestsForCommit', function () {
it('should return PRs linked to a commit', async function () {
// given
const repoOwner = 'github-owner';
const repoName = 'github-repository';
const commitSha = 'abc123';

// when
const response = await githubService.getPullRequestsForCommit(repoOwner, repoName, commitSha);
// then
expect(response).to.be.deep.equal([]);
});
});

describe('#hasConfigFileChangedInLatestRelease', function () {
const latestReleaseDate = '2020-08-13T04:45:06Z';
const secondToLastReleaseDate = '2020-08-10T12:45:06Z';
Expand Down

0 comments on commit 68be686

Please sign in to comment.