#23 Add create-issue command
Merged 6 years ago by lsedlar. Opened 6 years ago by hguemar.
hguemar/pag develop  into  develop

file modified
+1
@@ -33,6 +33,7 @@ 

  ]

  

  from .commands import create

+ from .commands import createissue

  from .commands import clone

  from .commands import fork

  from .commands import remote

file modified
+35
@@ -1,3 +1,5 @@ 

+ import re

+ 

  import bs4

  

  import fedora.client
@@ -54,6 +56,39 @@ 

                                        response, data))

          return repo_url(name)

  

+     def create_issue(self, repo, title, description, private=False):

+         if not self.is_logged_in:

+             raise PagureException('Not logged in.')

+ 

+         url = self.base_url + '/' + repo + '/new_issue'

+         response = self._session.get(url)

+         if not bool(response):

+             raise PagureException("Couldn't get form to get "

+                                   "csrf token %r" % response)

+ 

+         soup = bs4.BeautifulSoup(response.text, "html.parser")

+         data = {

+             'csrf_token' : soup.find(id='csrf_token').attrs['value'],

+             'title': title,

+             'issue_content': description,

+             'private': private

+         }

+ 

+         response = self._session.post(url, data=data)

+         if not bool(response):

+             del data['csrf_token']

+             raise PagureException('Bad status code from pagure when '

+                                   'forking project: %r.  Sent %r' % (

+                                       response, data))

+ 

+         soup = bs4.BeautifulSoup(response.text, "html.parser")

+         response_title = soup.title.string

+         match = re.match(r'Issue #(?P<issue_id>\d+):.*', response_title)

+         issue_id = match.group('issue_id')

+         issue_url = self.base_url + '/' + repo + '/issue/' + issue_id

+         return issue_url

+ 

+ 

      def fork(self, name):

          if not self.is_logged_in:

              raise PagureException('Not logged in.')

@@ -0,0 +1,28 @@ 

+ import getpass

+ 

+ import click

+ 

+ from pag.app import app

+ from pag.utils import (

+     configured,

+     assert_local_repo,

+     in_git_repo

+ )

+ from pag.client import client

+ 

+ @app.command('create-issue')

+ @click.option('-t', '--title', prompt=True)

+ @click.option('-d', '--description', prompt=True)

+ @click.option('-p', '--private', is_flag=True)

+ @configured

+ @assert_local_repo

+ def createissue(conf, title, description, private):

+     name = in_git_repo()

+ 

+     click.echo("Trying to create issue for %r in pagure.io" % name)

+     if not client.is_logged_in:

+         password = getpass.getpass("Fas password for %r" % conf['username'])

+         client.login(username=conf['username'], password=password)

+ 

+     message = client.create_issue(name, title, description, private)

+     click.echo("Created issue %s" % message)

rebased onto f070d0a

6 years ago

Thanks for catching this typo /o\ @lsedlar !

LGTM. @lsedlar, @hguemar - You two seem to be more focused on improving this tool than I am. It's yours! May I make you co-owners of the repo?

If user does not pass options for title or description, there's a traceback. Maybe adding prompt=True would be a good idea?

@ralph I think I already have access here, at least I see a merge button. The more the merrier :smile:

@ralph sure, I'm glad that there's another good reviewer around too! :) Pingou has given me some enhancement ideas for a late release.

@lsedlar: excellent catch, it's better this way!

rebased onto a3f3fad

6 years ago

I have no more comments. It works fine, and looks really useful. Let's merge it.

Pull-Request has been merged by lsedlar

6 years ago

@hguemar You should now have access to this repo.

You two should both have access to update the rpm now too: https://src.fedoraproject.org/rpms/pag