Skip to content

Commit

Permalink
Only consider commits before commitish, if provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Bulash committed Feb 7, 2022
1 parent 2f7ebf8 commit 5f02a3a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
31 changes: 26 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128613,6 +128613,7 @@ module.exports = (app, { getRouter }) => {
await findCommitsWithAssociatedPullRequests({
context,
ref,
up_to_commitish: commitish,
lastRelease,
config,
})
Expand Down Expand Up @@ -128787,6 +128788,7 @@ const findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ `
const findCommitsWithAssociatedPullRequests = async ({
context,
ref,
up_to_commitish,
lastRelease,
config,
}) => {
Expand All @@ -128803,17 +128805,35 @@ const findCommitsWithAssociatedPullRequests = async ({
const dataPath = ['repository', 'object', 'history']
const repoNameWithOwner = `${owner}/${repo}`

// Resolving commitish to a commit sha so that we can use it as a GraphQL cursor
let up_to_commit
if (up_to_commitish) {
let resolved_commitish = await context.octokit.repos.getCommit({
owner,
repo,
ref: up_to_commitish,
})
up_to_commit = resolved_commitish.data.sha
log({ context, message: `Including commits up to ${up_to_commit}` })
}

log({ context, message: `Fetching commits for reference ${ref}` })

let data, commits
if (lastRelease) {
log({
context,
message: `Fetching all commits for reference ${ref} since ${lastRelease.created_at}`,
message: `Including commits since ${lastRelease.created_at}`,
})

data = await paginate(
context.octokit.graphql,
findCommitsWithAssociatedPullRequestsQuery,
{ ...variables, since: lastRelease.created_at },
{
...variables,
since: lastRelease.created_at,
after: up_to_commit && `${up_to_commit} 0`,
},
dataPath
)
// GraphQL call is inclusive of commits from the specified dates. This means the final
Expand All @@ -128822,12 +128842,13 @@ const findCommitsWithAssociatedPullRequests = async ({
(commit) => commit.committedDate != lastRelease.created_at
)
} else {
log({ context, message: `Fetching all commits for reference ${ref}` })

data = await paginate(
context.octokit.graphql,
findCommitsWithAssociatedPullRequestsQuery,
variables,
{
...variables,
after: up_to_commit && `${up_to_commit} 0`,
},
dataPath
)
commits = _.get(data, [...dataPath, 'nodes'])
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ module.exports = (app, { getRouter }) => {
await findCommitsWithAssociatedPullRequests({
context,
ref,
up_to_commitish: commitish,
lastRelease,
config,
})
Expand Down
30 changes: 25 additions & 5 deletions lib/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ `
const findCommitsWithAssociatedPullRequests = async ({
context,
ref,
up_to_commitish,
lastRelease,
config,
}) => {
Expand All @@ -84,17 +85,35 @@ const findCommitsWithAssociatedPullRequests = async ({
const dataPath = ['repository', 'object', 'history']
const repoNameWithOwner = `${owner}/${repo}`

// Resolving commitish to a commit sha so that we can use it as a GraphQL cursor
let up_to_commit
if (up_to_commitish) {
let resolved_commitish = await context.octokit.repos.getCommit({
owner,
repo,
ref: up_to_commitish,
})
up_to_commit = resolved_commitish.data.sha
log({ context, message: `Including commits up to ${up_to_commit}` })
}

log({ context, message: `Fetching commits for reference ${ref}` })

let data, commits
if (lastRelease) {
log({
context,
message: `Fetching all commits for reference ${ref} since ${lastRelease.created_at}`,
message: `Including commits since ${lastRelease.created_at}`,
})

data = await paginate(
context.octokit.graphql,
findCommitsWithAssociatedPullRequestsQuery,
{ ...variables, since: lastRelease.created_at },
{
...variables,
since: lastRelease.created_at,
after: up_to_commit && `${up_to_commit} 0`,
},
dataPath
)
// GraphQL call is inclusive of commits from the specified dates. This means the final
Expand All @@ -103,12 +122,13 @@ const findCommitsWithAssociatedPullRequests = async ({
(commit) => commit.committedDate != lastRelease.created_at
)
} else {
log({ context, message: `Fetching all commits for reference ${ref}` })

data = await paginate(
context.octokit.graphql,
findCommitsWithAssociatedPullRequestsQuery,
variables,
{
...variables,
after: up_to_commit && `${up_to_commit} 0`,
},
dataPath
)
commits = _.get(data, [...dataPath, 'nodes'])
Expand Down

0 comments on commit 5f02a3a

Please sign in to comment.