From b248628a85be74bdd931252d75b0c661632a8099 Mon Sep 17 00:00:00 2001
From: Clement Verna <cverna@tutanota.com>
Date: May 30 2016 11:48:50 +0000
Subject: [PATCH 1/3] Added push command to push back temp ticket repo to pagure


---

diff --git a/pagure_importer/app.py b/pagure_importer/app.py
index 680de1c..1c2b507 100644
--- a/pagure_importer/app.py
+++ b/pagure_importer/app.py
@@ -16,6 +16,7 @@ __all__ = [
 from .commands import fedorahosted
 from .commands import github
 from .commands import clone
+from .commands import push
 
 if __name__ == '__main__':
     app()
diff --git a/pagure_importer/commands/push.py b/pagure_importer/commands/push.py
new file mode 100644
index 0000000..97b9705
--- /dev/null
+++ b/pagure_importer/commands/push.py
@@ -0,0 +1,16 @@
+import click
+import os
+import subprocess as sp
+from pagure_importer.app import app, REPO_PATH
+
+
+@app.command()
+@click.argument('repo_name')
+def push (repo_name):
+    repo = os.path.join(REPO_PATH, repo_name)
+    os.chdir(repo)
+    cmd = ['git', 'push', 'origin', 'master' ]
+    proc = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.STDOUT)
+    output, _ = proc.communicate()
+    output = output.decode('utf-8')
+    click.echo(output)

From b0fcbe932f2353ef001d1cf41e22a7fde6e1152d Mon Sep 17 00:00:00 2001
From: Clement Verna <cverna@tutanota.com>
Date: May 30 2016 12:16:06 +0000
Subject: [PATCH 2/3] Updated pgimport push usage in README


---

diff --git a/README.md b/README.md
index acd5132..6aa91fb 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@ CLI tool for importing issues etc. from different sources like github to pagure
 1. Activate the pagure tickets hook from project settings.
 2. Execute ```pgimport```. See Usage section
 3. Just answer what is asked. Check below instructions for particular source
-4. The script will make commits in your cloned bare repo: push the changes back to pagure.
+4. The script will make commits in your cloned repo: push the changes back to pagure. Use : ```pgimport push foobar.git```
 
 
 ## Usage
@@ -28,6 +28,7 @@ CLI tool for importing issues etc. from different sources like github to pagure
       clone
       fedorahosted
       github
+      push
 
 The clone command can be used to clone the pagure ticket repository:
 
@@ -51,6 +52,10 @@ The github command can be used to import issues from a github project to pagure
 
     $ pgimport github
 
+The push command can be used to push a clone pagure ticket repo back to pagure.
+
+    $ pgimport push foobar.git
+
 
 ### Tools used:
 ---

From b9b29571cd77e876c0147311aaa9d00498762398 Mon Sep 17 00:00:00 2001
From: Clement Verna <cverna@tutanota.com>
Date: May 31 2016 21:36:06 +0000
Subject: [PATCH 3/3] Cleanup the ticket repo display function.

Ask the user to enter a number rather than the repo name.

---

diff --git a/pagure_importer/commands/fedorahosted.py b/pagure_importer/commands/fedorahosted.py
index 9c50992..44c234a 100644
--- a/pagure_importer/commands/fedorahosted.py
+++ b/pagure_importer/commands/fedorahosted.py
@@ -20,8 +20,12 @@ def fedorahosted(project_url, tags):
     url_index = project_url.find('://')
     rpc_url = project_url[:url_index+3] + rpc_login +\
         project_url[url_index+3:] + '/login/xmlrpc'
-    pagure_importer.utils.display_repo()
-    repo_name = raw_input('Choose the import destination repo : ')
-    trac_importer = importer_trac.TracImporter(rpc_url, fasclient)
-    trac_importer.import_issues(repo_path=repo_name, repo_folder=REPO_PATH,
-                                tags=tags)
+    repos = pagure_importer.utils.display_repo()
+    if repos:
+        repo_index = raw_input('Choose the import destination repo (default 1) : ') or 1
+        repo_name = repos[int(repo_index)-1]
+        trac_importer = importer_trac.TracImporter(rpc_url, fasclient)
+        trac_importer.import_issues(repo_name=repo_name, repo_folder=REPO_PATH,
+                                    tags=tags)
+    else:
+        click.echo('No ticket repository found. Use pgimport clone command')
diff --git a/pagure_importer/utils/__init__.py b/pagure_importer/utils/__init__.py
index 5f3b2ae..94750fd 100644
--- a/pagure_importer/utils/__init__.py
+++ b/pagure_importer/utils/__init__.py
@@ -14,11 +14,16 @@ from pagure_importer.app import REPO_PATH
 
 
 def display_repo():
+    repo = []
+    index = 0
     print '#### Repo available ####'
     for file in os.listdir(REPO_PATH):
         if file.endswith('.git'):
-            print '  * ' + file
+            index += 1
+            print str(index) + ' - ' + file
+            repo.append(file)
     print
+    return repo
 
 
 def generate_json_for_github_contributors(github_username,
diff --git a/pagure_importer/utils/importer_trac.py b/pagure_importer/utils/importer_trac.py
index deb2cb8..b0ea1b5 100644
--- a/pagure_importer/utils/importer_trac.py
+++ b/pagure_importer/utils/importer_trac.py
@@ -10,7 +10,7 @@ class TracImporter():
         self.tracclient = ServerProxy(trac_project_url)
         self.fasclient = fasclient
 
-    def import_issues(self, repo_path, repo_folder, tags,
+    def import_issues(self, repo_name, repo_folder, tags,
                       trac_query='max=0&order=id'):
         '''Import issues from trac instance using xmlrpc API'''
         tickets_id = self.tracclient.ticket.query(trac_query)
@@ -28,6 +28,6 @@ class TracImporter():
             pagure_issue.comments = comments
 
             # update the local git repo
-            print 'Update repo with issue :' + str(ticket_id) + '/' +\
+            print 'Update ' + repo_name + ' with issue :' + str(ticket_id) + '/' +\
                 str(tickets_id[-1])
-            update_git(pagure_issue, repo_path, repo_folder)
+            update_git(pagure_issue, repo_name, repo_folder)

