#87 Add support for pagure custom close status
Merged 7 years ago by cverna. Opened 7 years ago by cverna.
cverna/pagure-importer support_custom_close  into  master

file modified
+21
@@ -20,6 +20,22 @@ 

  4. Just answer what is asked. Check below instructions for particular source

  5. The script will make commits in your cloned repo: push the changes back to pagure. Use : ```pgimport push foobar.git```

  

+ ## Custom Close Status

+ ---

+ pagure-importer creates a configuration under the home directory of the user $HOME/.pgimport. This configuration file contains the default close status.

+ If this file is not present run the following command.

+     ```$ pgimport mkconfig```

+ To add some new close status just edit the config file as follow. Where ```Foo``` is the pagure custom status and ```bar``` is the trac resolution status

+ 

+     [close_status]

+     Duplicate = ['duplicate']

+     Insufficient data = ['insufficient_info']

+     Invalid = ['invalid', 'wontfix', 'worksforme']

+     Foo = ['bar']

+ 

+     [github]

+     auth_token =

+ 

  

  ## Usage

  ---
@@ -35,6 +51,7 @@ 

        clone

        fedorahosted

        github

+       mkconfig

        push

  

  
@@ -83,6 +100,10 @@ 

  

      $ pgimport push foobar.git

  

+ 4) The mkconfig command will create a default config `.pgimport` file under the user $HOME directory.

+ 

+     $ pgimport mkconfig

+ 

  

  ### Migrate github issues to pagure

  ---

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

  import pagure_importer.commands.github

  import pagure_importer.commands.clone

  import pagure_importer.commands.push

+ import pagure_importer.commands.mkconfig

  

  if __name__ == '__main__':

      app()

@@ -1,5 +1,6 @@ 

  import csv

  import os

+ import sys

  import json

  import click

  import urlparse
@@ -10,6 +11,10 @@ 

  from pagure_importer.utils.exceptions import FileNotFound, EmailNotFound

  from pagure_importer.app import REPO_PATH

  

+ CFG_PATH = os.path.join(os.environ.get('HOME'), '.pgimport')

+ CONFIG = ConfigParser()

+ CONFIG.optionxform = str

+ 

  

  def create_auth_token(github):

      ''' Creates github authentication token. If Two Factor Authentication
@@ -27,21 +32,53 @@ 

      return otp_auth

  

  

+ def create_config():

+     '''Create the config file with default close statuses

+     and an empty github auth_token'''

+ 

+     CONFIG['close_status'] = {'Invalid': ['invalid', 'wontfix', 'worksforme'],

+                               'Insufficient data': ['insufficient_info'],

+                               'Duplicate': ['duplicate']}

+     CONFIG['github'] = {'auth_token': ''}

+     if os.path.exists(CFG_PATH):

+         if click.confirm('You already have a config file, if you continue '

+                          'your custom settings will be lost'):

+             with click.open_file(CFG_PATH, 'w+') as config_file:

+                 CONFIG.write(config_file)

+         else:

+             sys.exit(1)

+     else:

+         with click.open_file(CFG_PATH, 'w+') as config_file:

+             CONFIG.write(config_file)

+ 

+ 

+ def get_close_status():

+     ''' Read the config file and returns the close statuses'''

+ 

+     close_status = None

+     if os.path.exists(CFG_PATH):

+         CONFIG.read(CFG_PATH)

+         close_status = CONFIG['close_status']

+     else:

+         create_config()

+         CONFIG.read(CFG_PATH)

+         close_status = CONFIG['close_status']

+     return close_status

+ 

+ 

  def get_auth_token(github):

      ''' Checks the .pgimport file for github authentication key,

      if it is not present, creates it. '''

  

-     cfg_path = os.path.join(os.environ.get('HOME'), '.pgimport')

-     if os.path.exists(cfg_path):

-         parser = ConfigParser()

-         parser.read(cfg_path)

-         otp_auth = parser['github']['auth_token']

-     else:

-         otp_auth = create_auth_token(github)

-         otp_auth = otp_auth.token

-         with click.open_file(cfg_path, 'w+') as fp:

-             fp.write('[github] \nauth_token : %s' % otp_auth)

-     return otp_auth

+     if os.path.exists(CFG_PATH):

+         CONFIG.read(CFG_PATH)

+         otp_auth = CONFIG['github']['auth_token']

+         if not otp_auth:

+             otp_auth = create_auth_token(github)

+             CONFIG['github']['auth_token'] = otp_auth.token

+             with click.open_file(CFG_PATH, 'w+') as config_file:

+                 CONFIG.write(config_file)

+         return otp_auth

  

  

  def display_repo():

@@ -6,7 +6,7 @@ 

  import requests

  

  from datetime import datetime

- from pagure_importer.utils import get_pagure_namespace

+ from pagure_importer.utils import get_pagure_namespace, get_close_status

  from pagure_importer.utils.git import (

      clone_repo, get_secure_filename, push_delete_repo, update_git)

  from pagure_importer.utils.models import User, Issue, IssueComment
@@ -223,16 +223,18 @@ 

  

      def get_ticket_status(self, trac_ticket):

          ''' Returns the corresponding status of ticket on pagure '''

- 

-         if trac_ticket['status'] != 'closed':

-             return ('Open', '')

-         elif trac_ticket['resolution'] in ['invalid', 'wontfix',

-                                            'worksforme', 'duplicate']:

-             return ('Closed', 'Invalid')

-         elif trac_ticket['resolution'] == 'insufficient_info':

-             return ('Closed', 'Insufficient data')

+         close_status = get_close_status()

+         if close_status is not None:

+             if trac_ticket['status'] != 'closed':

+                 return ('Open', '')

+             else:

+                 for status in close_status:

+                     if trac_ticket['resolution'] in close_status[status]:

+                         return ('Closed', status)

+                 return ('Closed', 'Fixed')

          else:

-             return ('Closed', 'Fixed')

+             click.echo('ERROR: Close Status not read from config file')

+             sys.exit(1)

  

      def get_comment_user(self, comment):

          ''' Returns the user who commented on the ticket '''

Thi will allow a user to change the close status by edting a config file, before running the import.

rebased

7 years ago

5 new commits added

  • Create mkconfig command and managed error due to file missing
  • Modified get_tickets_status to use custom status
  • Add custom close status to readme
  • Adding Close status to config file
  • Modify existing close status to make more flexible
7 years ago

rebased

7 years ago

rebased

7 years ago

:thumbsup: (if you are okay without the doc strings. Rest should work well)

Thanks I will add the doc strings :smile:

1 new commit added

  • Added docstrings
7 years ago

Pull-Request has been merged by cverna

7 years ago