From 1477db66974db0eaf3c9b9b93bab624e3200b514 Mon Sep 17 00:00:00 2001 From: Vivek Anand Date: Dec 18 2016 19:06:27 +0000 Subject: [PATCH 1/4] Support for intra pagure import of exactly one issue --- diff --git a/pagure_importer/app.py b/pagure_importer/app.py index 1e110e3..f40d0d0 100644 --- a/pagure_importer/app.py +++ b/pagure_importer/app.py @@ -18,6 +18,7 @@ import pagure_importer.commands.github import pagure_importer.commands.clone import pagure_importer.commands.push import pagure_importer.commands.mkconfig +import pagure_importer.commands.intra_pagure if __name__ == '__main__': app() diff --git a/pagure_importer/commands/intra_pagure.py b/pagure_importer/commands/intra_pagure.py new file mode 100644 index 0000000..aa65702 --- /dev/null +++ b/pagure_importer/commands/intra_pagure.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# coding=utf-8 + +import click +import pagure_importer +from pagure_importer.app import app, REPO_PATH +from pagure_importer.utils import intra_pagure as ip + + +@app.command() +@click.option('--source', prompt="Source project with namespace and username") +@click.option('--issue_id', prompt="Issue id of the issue on source project") +def intra_pagure(source, issue_id): + ''' Command for intra project import of an issue ''' + + repos = pagure_importer.utils.display_repo() + if repos: + repo_index = click.prompt('Choose the import destination repo ', + default=1) + repo_name = repos[int(repo_index)-1] + intra_importer = ip.IntraPagureImporter( + source=source, + issue_id=issue_id + ) + intra_importer.import_issue( + repo_name=repo_name, + repo_folder=REPO_PATH + ) + else: + click.echo('No ticket repository found. Use pgimport clone command') diff --git a/pagure_importer/utils/intra_pagure.py b/pagure_importer/utils/intra_pagure.py new file mode 100644 index 0000000..26daba7 --- /dev/null +++ b/pagure_importer/utils/intra_pagure.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# coding=utf-8 + +import requests +from pagure_importer.utils.git import ( + clone_repo, push_delete_repo, update_git) +from pagure_importer.utils import models + + +class IntraPagureImporter(): + ''' For intra pagure imports of an issue ''' + + def __init__(self, source, issue_id): + self.source = source + self.source_issue_id = issue_id + self.request_url = 'https://pagure.io/api/0/%s/issue/%s' % \ + (self.source, self.source_issue_id) + + def import_issue(self, repo_name, repo_folder): + ''' Import the issue from the source project and create commits + locally ''' + + # get the issue + issue = requests.get(self.request_url).json() + issue_obj = models.Issue( + id=None, + title=issue.get('title'), + content=issue.get('title'), + status=issue.get('status'), + date_created=issue.get('date_created'), + user=issue.get('user'), + private=issue.get('private'), + attachment=issue.get('attachment'), + tags=issue.get('tags'), + depends=issue.get('depends'), + blocks=issue.get('blocks'), + assignee=issue.get('assignee'), + close_status=issue.get('close_status'), + comments=issue.get('comments'), + milestone=issue.get('milestone'), + custom_fields=issue.get('custom_fields'), + ) + newpath, new_repo = clone_repo(repo_name, repo_folder) + + # update the local git repo + new_repo = update_git(issue_obj, newpath, new_repo) + + # push and delete the cloned repo + push_delete_repo(newpath, new_repo) From 2b35b25e98e6a06a156ca3f7e322889ac8f9a353 Mon Sep 17 00:00:00 2001 From: Vivek Anand Date: Dec 18 2016 19:06:27 +0000 Subject: [PATCH 2/4] content is content not the title of the issue - intra pagure --- diff --git a/pagure_importer/utils/intra_pagure.py b/pagure_importer/utils/intra_pagure.py index 26daba7..14b7fc0 100644 --- a/pagure_importer/utils/intra_pagure.py +++ b/pagure_importer/utils/intra_pagure.py @@ -25,7 +25,7 @@ class IntraPagureImporter(): issue_obj = models.Issue( id=None, title=issue.get('title'), - content=issue.get('title'), + content=issue.get('content'), status=issue.get('status'), date_created=issue.get('date_created'), user=issue.get('user'), From 6c4c6aaa7b65854a26974d5ddaa9839c6f20f743 Mon Sep 17 00:00:00 2001 From: Vivek Anand Date: Dec 18 2016 19:46:28 +0000 Subject: [PATCH 3/4] Rename intra_pagure importer to 'pagure' --- diff --git a/pagure_importer/app.py b/pagure_importer/app.py index f40d0d0..cab8b60 100644 --- a/pagure_importer/app.py +++ b/pagure_importer/app.py @@ -18,7 +18,7 @@ import pagure_importer.commands.github import pagure_importer.commands.clone import pagure_importer.commands.push import pagure_importer.commands.mkconfig -import pagure_importer.commands.intra_pagure +import pagure_importer.commands.pagure if __name__ == '__main__': app() diff --git a/pagure_importer/commands/intra_pagure.py b/pagure_importer/commands/intra_pagure.py deleted file mode 100644 index aa65702..0000000 --- a/pagure_importer/commands/intra_pagure.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 - -import click -import pagure_importer -from pagure_importer.app import app, REPO_PATH -from pagure_importer.utils import intra_pagure as ip - - -@app.command() -@click.option('--source', prompt="Source project with namespace and username") -@click.option('--issue_id', prompt="Issue id of the issue on source project") -def intra_pagure(source, issue_id): - ''' Command for intra project import of an issue ''' - - repos = pagure_importer.utils.display_repo() - if repos: - repo_index = click.prompt('Choose the import destination repo ', - default=1) - repo_name = repos[int(repo_index)-1] - intra_importer = ip.IntraPagureImporter( - source=source, - issue_id=issue_id - ) - intra_importer.import_issue( - repo_name=repo_name, - repo_folder=REPO_PATH - ) - else: - click.echo('No ticket repository found. Use pgimport clone command') diff --git a/pagure_importer/commands/pagure.py b/pagure_importer/commands/pagure.py new file mode 100644 index 0000000..83893af --- /dev/null +++ b/pagure_importer/commands/pagure.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# coding=utf-8 + +import click +import pagure_importer +from pagure_importer.app import app, REPO_PATH +from pagure_importer.utils import intra_pagure as ip + + +@app.command() +@click.option('--source', prompt="Source project with namespace and username") +@click.option('--issue_id', prompt="Issue id of the issue on source project") +def pagure(source, issue_id): + ''' Command for intra project import of an issue ''' + + repos = pagure_importer.utils.display_repo() + if repos: + repo_index = click.prompt('Choose the import destination repo ', + default=1) + repo_name = repos[int(repo_index)-1] + intra_importer = ip.IntraPagureImporter( + source=source, + issue_id=issue_id + ) + intra_importer.import_issue( + repo_name=repo_name, + repo_folder=REPO_PATH + ) + else: + click.echo('No ticket repository found. Use pgimport clone command') From 08afe8182395f28c4827830943c7bc3afd9807a4 Mon Sep 17 00:00:00 2001 From: Vivek Anand Date: Dec 18 2016 19:56:46 +0000 Subject: [PATCH 4/4] add documentation on how to use intra pagure importer --- diff --git a/README.md b/README.md index 7c6fcbe..1aa736a 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,20 @@ To add some new close status just edit the config file as follow. Where ```Foo`` $ pgimport push foobar.git +### Migrate a ticket from one pagure project to other +--- +1) Clone the tickets git repository of the project you want to the issue be transfered to using: + $ pgimport clone ssh://git@pagure.io/tickets/foobar.git + + This will clone the pagure foobar repository into the default set /tmp directory as /tmp/foobar.git + +2) Use the ```pagure``` command to get the issue via the pagure api. Specify ```source``` and ```issue_id```. + $ pgimport pagure --source abcxyz --issue_id 567 + +3) The last command will create the issue to the local git repo you just cloned. Now push that repo to + create the issue on the destination project using: + $ pgimport push /tmp/foobar.git + ### Tools used: --- 1. [PyGithub](https://github.com/PyGithub/PyGithub) - a python library for [github](https://github.com/) api.