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

Feature/close draft pr #93

Merged
merged 21 commits into from
Jun 28, 2021
Merged

Feature/close draft pr #93

merged 21 commits into from
Jun 28, 2021

Conversation

ghinks
Copy link
Contributor

@ghinks ghinks commented Apr 10, 2021

Changes for issue 53

Both opens the draft PR on test and closes it on result

using --pullrequest, open to use of other names

goes in ontop of pull 91 tap update

raise a PR when the --pullrequest=true or if set in the wiby.json file.
add a body and title to the PR
remove the PR during the result scan
add tests for PR closing
@ghinks ghinks marked this pull request as draft April 10, 2021 11:15
change the status and the conclussion to values defined in

[checkrun definitio](https://docs.github.com/en/[email protected]/graphql/reference/objects#checkrun)
.wiby.json Outdated Show resolved Hide resolved
lib/github.js Outdated Show resolved Hide resolved
lib/result.js Outdated
@@ -37,6 +37,7 @@ module.exports = async function ({ dependents }) {
const parentBranchName = await context.getParentBranchName()
const branch = await context.getTestingBranchName(parentBranchName)
let resp = await github.getChecks(dependentPkgInfo.owner, dependentPkgInfo.name, branch)
await updatePRStatus(dependentPkgInfo.owner, dependentPkgInfo.name, branch, resp.data.check_runs)
Copy link
Member

@dominykas dominykas Apr 11, 2021

Choose a reason for hiding this comment

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

🤔

So we do have a wiby clean command, which deletes the branches. So maybe that's a better fit for this?

I'm kind of torn on whether the full wiby clean should happen automatically after the results are successful (it seems it now does it regardless of the result?) - I think if, as an implementer of a feature, I run wiby result, and there's a failure - I definitely want to keep things as is, so that I can go explore and debug. But if everything passed - I might still want to keep things around, if I'm building a feature that spans multiple repos?

Quite possibly this is a full-on separate feature and/or needs to be behind a global config flag (--auto-clean / autoClean in wiby.json or smth).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed.
Let me address the other issues in this draft PR. Then we can discuss further and maybe move it behind a different command.

@dominykas
Copy link
Member

dominykas commented Apr 11, 2021

👏 Thanks. sorry for not responding and not clarifying things earlier... I see there's some other discussions on the issue - will check those out now 👍

change updatePRStatus to closePR
change pullrequest to pull-request
change pullRequest (json) to pullRequest
change the pullRequest to be per dependent object
lib/test.js Outdated Show resolved Hide resolved
lib/result.js Outdated Show resolved Hide resolved
lib/result.js Outdated
}
const prsToClose = checkRuns.reduce((acc, check) => {
if (check.status === 'completed' &&
check.conclusion === 'success' &&
Copy link
Member

Choose a reason for hiding this comment

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

I forgot... do we not already have a helper function to verify if check has passed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure I see this else where?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, OK, the one we have is in a different context 👍

lib/test.js Outdated
`
const head = context.getTestingBranchName(parentBranchName)
const draft = true
const result = await github.createPR(dependentOwner, dependentRepo, title, head, parentBranchName, draft, body)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to set the base to parentBranchName here? I do have a note in the issues, that if the branch exists in the dependent repo as well as in parent repo, we should try to use that, but that's not implemented yet, so at this point parentBranchName likely does not even exist - we should probably keep it undefined (if the API allows it - otherwise we need to fetch the default branch name...)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was not sure on this comment, but its late afternoon so I'm taking it easy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dominykas ok, I came back to look at this comment and confess to not understanding at first you are referring to this I think issue 95. If so I think I understand.

Copy link
Member

@dominykas dominykas Apr 28, 2021

Choose a reason for hiding this comment

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

It's kind of related to that issue, but that's not exactly it.

When opening a PR, we want to merge head into base. So most of the time base should be main / master (i.e. default branch), not parentBranchName?

  1. Suppose you're working on my-feature
  2. You wiby test
  3. A wiby-my-feature branch is created in the dependent repo
  4. You should be opening a PR on the dependent repo to merge wiby-my-feature into main

i.e. my-feature (parentBranchName) will not even exist in the dependent, most of the time. When it does - we do have the "existing branches" case, which needs to be thought through - most likely we'll want to create a wiby-my-feature in the dependent, but we will not start it at main / master, but at my-feature instead. In that case, there could be some DX wins if the PR on the dependent tried to merge wiby-my-feature into my-feature, but at the same time - if it tries to merge wiby-my-feature into main, it's probably no big deal either?

This is hard 😅

Copy link
Member

Choose a reason for hiding this comment

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

To simplify this - I think initially the base param should always be empty (if GH will accept that), and the rest should be addressed as we tackle the existing branches case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not quite done yet, I'm going for the merging into the default branch main or whatever the default is set to. ( the better DX experience needs another change which I'm going to try for tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dominykas , I altered the code to raise the PR against the default branch and added changes to the tests to cover this most simple scenario. I too want to get this PR merged and maybe covering the other edge cases should be handled in another follow up PR?

@ghinks
Copy link
Contributor Author

ghinks commented Apr 18, 2021

I'm redoing this with the suggestions that it be a different feature flag.
I will incorporate the comments you made above.
The tough part is the new feature name

  • close-pr
  • auto-clean
    ...
    always tough to give things names

I am going to merge the changes I have made back into this PR now. We may need to re-review it.

add new feature flag...
for PR removal
add small amount of text output for success case with the intent of adding proper processing next.
lint fixes
updates to names and suggestions from feedback
add a TODO to remind me to create a processOutput for the close-pr command
@ghinks ghinks mentioned this pull request Apr 22, 2021
@dominykas
Copy link
Member

🤔 I see you added close-pr as a new command. I guess it might be useful on its own. 👍

That said, I think we probably still need to add it into wiby clean as well? Because wiby clean won't be able to delete branches if they have PRs open.

@@ -32,6 +32,9 @@ module.exports = async function ({ dependents }) {

const patchedPackageJSON = applyPatch(parentDependencyLink, parentPkgJSON.name, dependentPkgJson, parentPkgJSON.name)
await pushPatch(patchedPackageJSON, dependentRepositoryInfo.owner, dependentRepositoryInfo.name, parentPkgJSON.name, parentBranchName)
if (pullRequest) {
Copy link
Member

Choose a reason for hiding this comment

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

Updated #95 (comment) - if we think that's the right approach, then we should check if the PR is already open here (we need to open a new one if it's closed).

I can't recall if the GH API returns the PR list as part of the "get branch" API call, or if there's a separate API call for that...

Copy link
Contributor Author

@ghinks ghinks Apr 28, 2021

Choose a reason for hiding this comment

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

Ok. I agree that clean needs it to. I'll merge the latest changes back into my branch and carry on.

One other thing occurred to me. We may want to be using the Promise.allSettled() module as if we checking upon multiple checks. But that can be for later.

Copy link
Member

Choose a reason for hiding this comment

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

Promise.allSettled()

Yeah, that probably makes sense.

Copy link
Contributor Author

@ghinks ghinks Apr 29, 2021

Choose a reason for hiding this comment

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

After looking at the needs of the clean command. I do not think we need to do anything. If the branch is deleted during a clean then the PR that was raised against that branch to trigger an action is also deleted.

If you agree with my opinion I'll look at issue 95 with respect to the close-pr command.

add TODO noting that the run checks could be > 1 for a branch
and that some could pass and some could fail and we need to
handle that case
# Conflicts:
#	test/cli/test.js
@ghinks ghinks marked this pull request as ready for review May 5, 2021 10:43
bin/commands/close-pr.js Outdated Show resolved Hide resolved
Co-authored-by: Dominykas Blyžė <[email protected]>
@ghinks
Copy link
Contributor Author

ghinks commented May 12, 2021

many thanks for the reviews

@dominykas
Copy link
Member

I'm keen to merge this, but #93 (comment) is not yet resolved? (the parentBranchName thread)

@ghinks
Copy link
Contributor Author

ghinks commented May 17, 2021

I'll look at this with respect to #93 tomorrow. Today I need to prep or the talk for OpenJSWorld.

PR should be raised against the default branch

this could be main. Next handle the case that the

feature branch is already there.
test that the parent branch exists or not in the dependent.

If the dependency parent branch exists in the dependent use that
branch and raise a PR of wiby-feature-x into feature-x rather than into the default branch.
rationalize repeated nock code block into a beforeEach clause.
@ghinks
Copy link
Contributor Author

ghinks commented May 22, 2021

@dominykas I had some extra time so I have addressed the case where the dependency feature branch name could be pre-existing in the dependent repo, and altered the PR raised to be wiby-feature-x into feature-x in that case.

@dominykas
Copy link
Member

wiby test

@dominykas
Copy link
Member

(don't really expect ☝️ to work, but still hoping that maybe GH fixed the issue I was having...)

@dominykas dominykas merged commit b0fb895 into pkgjs:main Jun 28, 2021
@dominykas
Copy link
Member

🎉 This PR is included in version 0.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants