labhub.py: add migrate_issue plugin - #521
Conversation
| ) | ||
| yield reply | ||
|
|
||
| @re_botcmd(pattern=r'^migrate\s+https://github.com/([^/]+)/([^/]+)/+issues/(\d+)\s+https://github.com/([^/]+)/([^/]+)/*$', # Ignore LineLengthBear, PyCodeStyleBear |
There was a problem hiding this comment.
Please make this workable for gitlab repos as well. The whole point of labhub is to provide a unified front for both GitHub and GitLab, and hence the name LabHub 😉
| yield 'Second repository not owned by our org.' | ||
| return | ||
|
|
||
| if (repo_name_orig in self.REPOS) and (repo_name_final in self.REPOS): |
There was a problem hiding this comment.
use, if not... so we can remove the reduntant if block and the contained pass statement
| yield 'Repository does not exist!' | ||
| return | ||
|
|
||
| if self.TEAMS[self.GH_ORG_NAME + ' maintainers'].is_member(user): |
| old_labels = old_issue.labels | ||
|
|
||
| except RuntimeError: | ||
| yield 'Issue does not exist!' |
There was a problem hiding this comment.
RuntimeError in IGitt is not always 404s 😅
| if str(old_issue.state) == 'closed': | ||
| yield 'Issue cannot be migrated as it has been closed already.' | ||
| return | ||
| else: |
There was a problem hiding this comment.
else block is not needed, remove it
| url1 = 'https://github.com/{}/{}/issues/{}' | ||
| new_issue_title = old_issue.title | ||
| new_issue_description = old_issue.description.rstrip() | ||
| extra_msg = '\n\nMigrated issue from '+url1.format( |
There was a problem hiding this comment.
maybe include the author as well? Migrate issue opened by @author from ... so the author the issue follows new issue as well
There was a problem hiding this comment.
I was trying the same, but there seems to be some problem with the IGitt module I have installed on my system using pip, as it says author of the issue is not an attribute even though I find this method here: https://gitlab.com/gitmate/open-source/IGitt/blob/master/IGitt/GitHub/GitHubIssue.py and I am not particularly sure why but might be some problem with my system... 😅

| ' by @' + str(user) | ||
|
|
||
| new_issue = self.REPOS[repo_name_final].create_issue( | ||
| new_issue_title, new_issue_description+extra_msg) |
There was a problem hiding this comment.
Just concatenate this above, concatenation in function args doesn't look good and is confusing
|
|
||
| old_comm = old_issue.comments | ||
|
|
||
| for i in range(len(old_comm)): |
There was a problem hiding this comment.
use for comment in old_issue.comments and get rid of few lines of code here 😉
| yield 'Second repository not owned by our org.' | ||
| return | ||
|
|
||
| if (repo_name_orig not in self.REPOS) or (repo_name_final not in self.REPOS): |
There was a problem hiding this comment.
Line is longer than allowed. (85 > 80)
Origin: LineLengthBear, Section: all.linelength.
| yield 'Repository does not exist!' | ||
| return | ||
|
|
||
| if (self.TEAMS[self.GH_ORG_NAME + ' maintainers'].is_member(user) == False): |
There was a problem hiding this comment.
Line is longer than allowed. (84 > 80)
Origin: LineLengthBear, Section: all.linelength.
| new_issue_title = old_issue.title | ||
| new_issue_description = old_issue.description.rstrip() | ||
| issue_author = old_issue.author.username | ||
| extra_msg = '\n\nMigrated issue originally opened by @' + issue_author + \ |
There was a problem hiding this comment.
Line is longer than allowed. (82 > 80)
Origin: LineLengthBear, Section: all.linelength.
|
|
||
| for comment in old_issue.comments: | ||
| comm_text = comment.body.rstrip() | ||
| comm_url = url1.format(orig_host, org, repo_name_orig, issue_number) + \ |
There was a problem hiding this comment.
Line is longer than allowed. (84 > 80)
Origin: LineLengthBear, Section: all.linelength.
| comm_url = url1.format(orig_host, org, repo_name_orig, issue_number) + \ | ||
| '#issuecomment-' + str(comment.number) | ||
| new_body = comm_text + '\n\nOriginally written by @' + \ | ||
| comment.author.username + ' on ' + str(comment.updated) + ' UTC' + \ |
There was a problem hiding this comment.
Line is longer than allowed. (84 > 80)
Origin: LineLengthBear, Section: all.linelength.
| url2 = 'https://{}.com/{}/{}/issues/{}'.format( | ||
| final_host, org, repo_name_final, new_issue.number) | ||
|
|
||
| migrated_comment = 'Issue has been migrated to another [repository](' + \ |
There was a problem hiding this comment.
Line is longer than allowed. (81 > 80)
Origin: LineLengthBear, Section: all.linelength.
|
Requested changes made, @meetmangukiya |
f03dd02 to
6b8f154
Compare
|
|
||
| self.mock_org = create_autospec(github3.orgs.Organization) | ||
| self.mock_gh = create_autospec(github3.GitHub) | ||
|
|
| mock_maint_team.is_member.return_value = False | ||
|
|
||
| labhub.TEAMS = { | ||
| 'coala maintainers': mock_maint_team, |
| # No issue exists | ||
| mock_maint_team.is_member.return_value = True | ||
| self.mock_repo.get_issue = Mock(side_effect=RuntimeError('Error message',404)) | ||
| testbot.assertCommand(cmd.format('coala', 'a', '21','coala','b'), |
| 'has been closed already') | ||
| # Migrate issue | ||
| mock_maint_team.is_member.return_value = True | ||
| mock_iss = create_autospec(IGitt.GitHub.GitHub.GitHubIssue) |
There was a problem hiding this comment.
use mock_issue instead of shorted name
|
Requested changes made, @jayvdb |
| # Migrate issue | ||
| mock_maint_team.is_member.return_value = True | ||
| mock_issue = create_autospec(IGitt.GitHub.GitHub.GitHubIssue) | ||
| issue2 = create_autospec(IGitt.GitHub.GitHub.GitHubIssue) |
There was a problem hiding this comment.
why is one called mock_issue and the other issue2? that is confusing.
| try: | ||
| assert org == self.GH_ORG_NAME or org == self.GL_ORG_NAME | ||
| except AssertionError: | ||
| yield 'First repository not owned by our org.' |
There was a problem hiding this comment.
First & second -> source & target
| org2 = match.group(6) | ||
| repo_name_final = match.group(7) | ||
|
|
||
| try: |
| yield 'Issue cannot be migrated as it has been closed already.' | ||
| return | ||
|
|
||
| url1 = 'https://{}.com/{}/{}/issues/{}' |
There was a problem hiding this comment.
this isnt a url .. it is a format string.
confusing because here url1 is a format string, but below url2 is a real complete url.
| new_issue_title = old_issue.title | ||
| new_issue_description = old_issue.description.rstrip() + '\n\n' | ||
| issue_author = old_issue.author.username | ||
| ext_msg = 'Migrated issue originally opened by @' + issue_author + \ |
There was a problem hiding this comment.
pls dont use line continuations (\)
| else: | ||
| raise RuntimeError(sterr, errno) | ||
|
|
||
| if str(old_issue.state) == 'closed': |
There was a problem hiding this comment.
it is safer to check that it is open.
then new states wont surprise everyone.
| try: | ||
| assert org2 == self.GH_ORG_NAME or org2 == self.GL_ORG_NAME | ||
| except AssertionError: | ||
| yield 'Second repository not owned by our org.' |
There was a problem hiding this comment.
If there is only one message, you can use return 'foo' instead of yield & return
|
Changes made @jayvdb |
| org = match.group(2) | ||
| repo_name_orig = match.group(3) | ||
| issue_number = match.group(4) | ||
| user = msg.frm.nick |
There was a problem hiding this comment.
it is a bit strange seeing this variable mixed in amoung all the regex matches.
please read every line of your diff and ask yourself if it can be improved.
|
Made changes as requested, @jayvdb |
| ) | ||
| yield reply | ||
|
|
||
| @re_botcmd(pattern=r'^migrate\s+https://(github|gitlab)\.com/([^/]+)/([^/]+)/+issues/(\d+)\s+https://(github|gitlab)\.com/([^/]+)/([^/]+)/*$', # Ignore LineLengthBear, PyCodeStyleBear |
There was a problem hiding this comment.
the regex won't work for gitlab sub groups, see regex for other commands to see how its done
There was a problem hiding this comment.
Since this regex is most likely be duplicated in every command, make a new constant with the regex to match github/gitlab url, and then append it to your command. Do this as part of another issue after this is complete 😉
There was a problem hiding this comment.
@meetmangukiya , I used the same regex as used in unassign_cmd and it uses the same regex. How should I go about this? 😕
There was a problem hiding this comment.
What about we only capture the URL here, without using regex to parse it, and then split it with a helper function that can be re-used in each command which takes a git hoster URL ?
| if target_repo not in self.REPOS: | ||
| return 'Target repository does not exist.' | ||
|
|
||
| # Ignore LineLengthBear, PyCodeStyleBear |
| source_url = 'https://{}.com/{}/{}/issues/{}'.format( | ||
| source_host, source_org, source_repo, issue_number) | ||
|
|
||
| # Ignore LineLengthBear, PyCodeStyleBear |
There was a problem hiding this comment.
Remove this and make the string multiline, something like
a = ('some long string which doesnt fit in 80 chars'
'Next part of the string. This both will be concantenated into one')
| source_issue.title, target_issue_desc) | ||
| target_issue.labels = source_labels | ||
|
|
||
| # Ignore LineLengthBear, PyCodeStyleBear |
| comment_ext = '\n\nOriginally commented by @{} on {} UTC and can be seen [here]({})' | ||
|
|
||
| for comment in source_issue.comments: | ||
| comm_url = source_url + '#issuecomment-' + str(comment.number) |
There was a problem hiding this comment.
I don't think this is the case for gitlab comments, use IGitt API to get comment link, if it doesn't exist, make upstream contribution
There was a problem hiding this comment.
Will be excluding the comment URLs for the current PR and will make another PR when upstream contribution in IGitt is made.
| target_issue.labels = source_labels | ||
|
|
||
| # Ignore LineLengthBear, PyCodeStyleBear | ||
| comment_ext = '\n\nOriginally commented by @{} on {} UTC and can be seen [here]({})' |
There was a problem hiding this comment.
Are you sure the time returned has no UTC offset?
There was a problem hiding this comment.
I tested it on it on my own forks and there was no UTC offset included there. However, I wasn't able to find documentation explicitly mentioning anything about offsets 😅
|
Will do @meetmangukiya |
|
@random-access7 can you please make the requested changes? |
|
@nvzard, will do by tonight. |
migrate_issue plugin that adds ability to migrate an issue from a source repo to target repo, both owned by the org. Issue title, issue description and all comments are copied with a few additional details appended to the description and comments. Source issue is referenced in the target issue and closed after the migration is completed. Closes coala#518
|
@gitmate-bot rebase |
|
Hey! I'm GitMate.io! This pull request is being rebased automatically. Please DO NOT push while rebase is in progress or your changes would be lost permanently |
|
Automated rebase failed! Please rebase your pull request manually via the command line. Reason: |
|
@random-access7 can you please resolve the merge conflicts? And we will make sure it merges before anything else so it doesn't lead to more conflicts |
Introduce migrate_issue plugin that adds ability
to migrate an issue from a source repo to target
repo, both owned by the org.
Issue title, issue description and all comments
are copied with a few additional details appended to
the the description and comments. Source issue is
referenced in the target issue and is closed after
the migration is complete.
Closes #518
Reviewers Checklist
botcmdandre_botcmddecorators.