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

Only consider commits before commitish, if provided #1058

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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}`

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

// 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}` })
}

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}`

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

// 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}` })
}

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