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

Allow for deleting and restoring branch associated with PR #1784

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

austinsasko
Copy link

@austinsasko austinsasko commented Dec 14, 2020

Adding logic for deleting/restoring branches associated with a PR, as well as forcing a delete.
Fixes #580

@austinsasko austinsasko changed the title Fixes #580 Implementing logic for deleting and restoring a branch associated with a PR Dec 14, 2020
Copy link
Collaborator

@s-t-e-v-e-n-k s-t-e-v-e-n-k left a comment

Choose a reason for hiding this comment

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

This is looking like a great start, I have some concerns I have outlined.

github/PullRequest.py Outdated Show resolved Hide resolved
github/PullRequest.py Outdated Show resolved Hide resolved
github/PullRequest.py Outdated Show resolved Hide resolved
tests/PullRequest.py Outdated Show resolved Hide resolved
tests/PullRequest.py Outdated Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Dec 24, 2020

Codecov Report

Merging #1784 (16b2544) into master (34d097c) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1784   +/-   ##
=======================================
  Coverage   98.76%   98.76%           
=======================================
  Files          51       51           
  Lines        2677     2677           
=======================================
  Hits         2644     2644           
  Misses         33       33           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 34d097c...16b2544. Read the comment docs.

@austinsasko austinsasko force-pushed the feature/adding-delete-restore-logic branch 3 times, most recently from a254363 to fee99a2 Compare December 24, 2020 01:02
@austinsasko austinsasko force-pushed the feature/adding-delete-restore-logic branch from fee99a2 to f299699 Compare December 24, 2020 01:25
@austinsasko austinsasko reopened this Dec 24, 2020
@austinsasko
Copy link
Author

austinsasko commented Dec 24, 2020

@s-t-e-v-e-n-k I am trying to figure out why code coverage decreased on a file that I did not interface with or modify any tests that interacted with it. Any ideas?

Update: It appears the changes in #1797 will bring the code coverage back to up to the place it should be. I believe the latest pyJWT being released yesterday is causing codecov to not reach that line in MainClass.py -- as long as that PR (1797) is merged before this one, I think that codecoverage wont be affected. Apologies for any spam that I caused by troubleshooting that.

austinsasko and others added 2 commits December 28, 2020 14:34
* Fixes PyGithub#580 -- adding logic for deleting/restoring branches associated with a PR, as well as forcing a delete. Automated tests added too

* Adding black formatting and cleansing PII to the best of my ability

* CI failure fix - isort formatting, import moved up in the file

* fixing additional requests and adding docstrings

* Accounting for CI test for pyupgrade
@austinsasko austinsasko force-pushed the feature/adding-delete-restore-logic branch from dd0718d to 16b2544 Compare December 28, 2020 19:35
@austinsasko
Copy link
Author

austinsasko commented Dec 28, 2020

As believed, now that the other PR has been merged (and upon me pulling latest master into my branch) this one is ready to be merged as well with no issues :)
@s-t-e-v-e-n-k do you need anything else from me?

Thanks

@austinsasko
Copy link
Author

@s-t-e-v-e-n-k @sfdye Is there anything else in this PR needing changes?

Copy link
Collaborator

@s-t-e-v-e-n-k s-t-e-v-e-n-k left a comment

Choose a reason for hiding this comment

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

This is looking like a good start, I have some concerns inline.

github/PullRequest.py Outdated Show resolved Hide resolved
github/PullRequest.py Outdated Show resolved Hide resolved
github/PullRequest.py Outdated Show resolved Hide resolved
github/PullRequest.py Outdated Show resolved Hide resolved
github/PullRequest.py Outdated Show resolved Hide resolved
github/PullRequest.py Outdated Show resolved Hide resolved
github/PullRequest.py Outdated Show resolved Hide resolved
tests/PullRequest.py Outdated Show resolved Hide resolved
tests/PullRequest.py Outdated Show resolved Hide resolved
@austinsasko
Copy link
Author

@s-t-e-v-e-n-k 👍 applied your recommendations

Copy link
Collaborator

@s-t-e-v-e-n-k s-t-e-v-e-n-k left a comment

Choose a reason for hiding this comment

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

Thanks for your changes, you're making good progress, some more changes required, though.

github/PullRequest.py Outdated Show resolved Hide resolved
github/PullRequest.py Outdated Show resolved Hide resolved
github/PullRequest.py Outdated Show resolved Hide resolved
tests/PullRequest.py Show resolved Hide resolved
tests/PullRequest.py Show resolved Hide resolved
tests/PullRequest.py Show resolved Hide resolved
@austinsasko austinsasko deleted the feature/adding-delete-restore-logic branch March 29, 2021 17:32
@austinsasko austinsasko restored the feature/adding-delete-restore-logic branch March 29, 2021 17:33
@austinsasko austinsasko reopened this Mar 29, 2021
@austinsasko
Copy link
Author

@s-t-e-v-e-n-k removing import github breaks the CI tests. I re-added it and the tests are passing.

@Seluj78
Copy link

Seluj78 commented Apr 24, 2021

Hi ! any news on this ? I'd love to implement it on https://github.com/AFPy/PyDocTeur :)

@austinsasko
Copy link
Author

@s-t-e-v-e-n-k

@austinsasko
Copy link
Author

@sfdye anything we can do here?

@austinsasko
Copy link
Author

@s-t-e-v-e-n-k @sfdye

@austinsasko
Copy link
Author

@s-t-e-v-e-n-k @sfdye who maintains this project currently, if anyone?

@austinsasko
Copy link
Author

@s-t-e-v-e-n-k @sfdye hoping to make one last ditch effort to follow up

@austinsasko
Copy link
Author

@JLLeitschuh @EnricoMi
Are you guys able to review this?

Thanks

@@ -835,12 +835,35 @@ def is_merged(self):
status, headers, data = self._requester.requestJson("GET", self.url + "/merge")
return status == 204

def restore_branch(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing .pyi file API addition

def merge(
self,
commit_message=github.GithubObject.NotSet,
commit_title=github.GithubObject.NotSet,
merge_method=github.GithubObject.NotSet,
sha=github.GithubObject.NotSet,
deletebranch=False,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing .pyi file API modification

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
deletebranch=False,
delete_branch=False,

f"refs/heads/{self.head.ref}", sha=self.head.sha
)

def delete_branch(self, force=False):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing .pyi file API addition

@EnricoMi EnricoMi changed the title Implementing logic for deleting and restoring a branch associated with a PR Allow for deleting and restoring branch associated with PR Jun 28, 2023
Comment on lines +898 to +900
if deletebranch:
self.delete_branch()

Copy link
Collaborator

Choose a reason for hiding this comment

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

To be honest, I don't like adding this side-effect here. Given we have delete_branch, it is very easy for users to delete the branch with a single line after merge returned. When more pull requests remain, delete_branch raises an error and call site does not get the successful PullRequestMergeStatus response.

Comment on lines +855 to +857
raise AttributeError(
"PRs referencing this branch remain. Not deleting the branch"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would not call this AttributeError, because the values of the attributes are right, This is more a RuntimeError, as delete_branch(force=False) should not be called as long as there exist pull requests.

Suggested change
raise AttributeError(
"PRs referencing this branch remain. Not deleting the branch"
)
raise RuntimeError(
"This branch is referenced by open pull requests, set force=True to delete this branch."
)

def delete_branch(self, force=False):
"""
Convenience function that calls :meth:`GitRef.delete`
:rtype: bool
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add some notes on the semantics of force.

self.assertTrue(
self.delete_restore_repo.get_branch(self.delete_restore_pull.head.ref)
)
self.assertIs(self.delete_restore_pull.delete_branch(force=False), None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this assertion?

Suggested change
self.assertIs(self.delete_restore_pull.delete_branch(force=False), None)
self.delete_restore_pull.delete_branch(force=False)

@treee111
Copy link
Contributor

@austinsasko seams you have to integrate the latest changes from main into your branch. Also some review comments are waiting to be integrated. Would be nice to see further progress here 🔢

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

Successfully merging this pull request may close these issues.

Delete/restore branch associated with a pull request
7 participants