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

Filter PRs from forks #251

Merged
merged 3 commits into from
May 26, 2020
Merged
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
45 changes: 33 additions & 12 deletions bin/generate-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const path = require('path')
const fetch = require('node-fetch')
const { findCommitsWithAssociatedPullRequestsQuery } = require('../lib/commits')

const REPO_OWNER = 'TimonVS'
const REPO_NAME = 'release-drafter-test-repo'
const GITHUB_GRAPHQL_API_ENDPOINT = 'https://api.github.com/graphql'
const GITHUB_TOKEN = process.env.GITHUB_TOKEN
Expand All @@ -16,14 +15,30 @@ if (!GITHUB_TOKEN) {
)
}

const branches = [
'merge-commit',
'rebase-merging',
'squash-merging',
'overlapping-label',
const repos = [
{
owner: 'TimonVS',
branch: 'merge-commit',
},
{
owner: 'TimonVS',
branch: 'rebase-merging',
},
{
owner: 'TimonVS',
branch: 'squash-merging',
},
{
owner: 'TimonVS',
branch: 'overlapping-label',
},
{
owner: 'jetersen',
branch: 'forking',
Comment on lines +36 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reason for this was because associated PRs does not immediately appear on the main repo or at least that was the behavior I saw.

},
]

branches.forEach((branch) => {
repos.forEach((repo) => {
const options = {
method: 'POST',
headers: {
Expand All @@ -33,24 +48,30 @@ branches.forEach((branch) => {
body: JSON.stringify({
query: findCommitsWithAssociatedPullRequestsQuery,
variables: {
owner: REPO_OWNER,
owner: repo.owner,
name: REPO_NAME,
branch,
withPullRequestBody: true
branch: repo.branch,
withPullRequestBody: true,
},
}),
}

fetch(GITHUB_GRAPHQL_API_ENDPOINT, options)
.then((response) => response.json())
.then((data) => {
// hack the generated to reduce massive rewrite inside the tests
// basically duplicating the possible configs 🤯
let string = JSON.stringify(data, null, 2).replace(
/TimonVS\/release-drafter-test-repo/g,
'toolmantim/release-drafter-test-project'
)
fs.writeFileSync(
path.resolve(
__dirname,
'../test/fixtures/__generated__',
`graphql-commits-${branch}.json`
`graphql-commits-${repo.branch}.json`
),
JSON.stringify(data, null, 2) + '\n'
string + '\n'
)
})
.catch(console.error)
Expand Down
6 changes: 5 additions & 1 deletion lib/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ module.exports.findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ `
author {
login
}
baseRepository {
nameWithOwner
}
mergedAt
isCrossRepository
labels(first: 10) {
Expand Down Expand Up @@ -71,6 +74,7 @@ module.exports.findCommitsWithAssociatedPullRequests = async ({
withPullRequestBody: config['change-template'].includes('$BODY'),
}
const dataPath = ['repository', 'ref', 'target', 'history']
const repoNameWithOwner = `${owner}/${repo}`

let data
if (lastRelease) {
Expand Down Expand Up @@ -101,7 +105,7 @@ module.exports.findCommitsWithAssociatedPullRequests = async ({
const pullRequests = _.uniqBy(
_.flatten(commits.map((commit) => commit.associatedPullRequests.nodes)),
'number'
)
).filter((pr) => pr.baseRepository.nameWithOwner === repoNameWithOwner)

return { commits, pullRequests }
}