From 8174c2d4021e1c2dd25d259dd15c738e5af394d6 Mon Sep 17 00:00:00 2001
From: Dusty Mabe <dusty@dustymabe.com>
Date: Aug 12 2019 12:07:31 +0000
Subject: [PATCH 1/3] switch from libpagure to ogr


Switched to ogr which seems to have more active development
and is being maintained right now. https://github.com/packit-service/ogr

Fixes #20

Signed-off-by: Dusty Mabe <dusty@dustymabe.com>

---

diff --git a/compose_tracker.py b/compose_tracker.py
index 7d4b5d2..897e27d 100755
--- a/compose_tracker.py
+++ b/compose_tracker.py
@@ -24,7 +24,7 @@ import re
 import requests
 import sys
 
-from libpagure import Pagure
+from ogr import PagureService
 
 # Set local logging 
 logger = logging.getLogger(__name__)
@@ -32,8 +32,9 @@ logger.setLevel(logging.INFO)
 
 
 # Connect to pagure and set it to point to our repo
-DEFAULT_PAGURE_DOMAIN = 'https://pagure.io/'
-DEFAULT_PAGURE_REPO = 'releng/failed-composes'
+DEFAULT_PAGURE_DOMAIN    = 'https://pagure.io/'
+DEFAULT_PAGURE_NAMESPACE = 'releng'
+DEFAULT_PAGURE_REPO      = 'failed-composes'
 
 # URL for linking to koji tasks by ID
 KOJI_TASK_URL='https://koji.fedoraproject.org/koji/taskinfo?taskID='
@@ -60,19 +61,26 @@ EXAMPLE_MESSAGE_BODY = json.loads("""
 class Consumer(object):
     def __init__(self):
         self.token = os.getenv('PAGURE_TOKEN')
-        self.pagure_domain = os.getenv('PAGURE_DOMAIN', DEFAULT_PAGURE_DOMAIN)
+        pagure_domain    = os.getenv('PAGURE_DOMAIN',    DEFAULT_PAGURE_DOMAIN)
+        pagure_namespace = os.getenv('PAGURE_NAMESPACE', DEFAULT_PAGURE_NAMESPACE) 
+        pagure_repo      = os.getenv('PAGURE_REPO',      DEFAULT_PAGURE_REPO) 
+
         if self.token:
             logger.info("Using detected token to talk to pagure.") 
-            self.pg = Pagure(instance_url=self.pagure_domain,
-                             pagure_token=self.token)
+            gitservice = PagureService(
+                            token=self.token,
+                            instance_url=pagure_domain)
         else:
             logger.info("No pagure token was detected.") 
             logger.info("This script will run but won't be able to create new issues.")
-            self.pg = Pagure(instance_url=self.pagure_domain)
+            gitservice = PagureService(instance_url=pagure_domain)
 
 
-        # Set the repo to create new issues against
-        self.pg.repo = os.getenv('PAGURE_REPO', DEFAULT_PAGURE_REPO)
+        # Grab the project to create new issues against
+        logger.info(f'Targeting repo {pagure_namespace}/{pagure_repo} on {pagure_domain}')
+        self.gitproject = gitservice.get_project(
+                            repo=pagure_repo,
+                            namespace=pagure_namespace)
 
         # Used for printing out a value when the day has changed
         self.date = datetime.date.today()
@@ -192,7 +200,7 @@ class Consumer(object):
         # Should be able to do this now https://pagure.io/libpagure/issue/31
 
         if self.token:
-            self.pg.create_issue(title=title, content=content)
+            self.gitproject.create_issue(title=title, body=content)
 
 # The code in this file is expected to be run through fedora messaging
 # However, you can run the script directly for testing purposes. The

From ec150acc6bc1911c1b55aa5241cadeb1177d48d9 Mon Sep 17 00:00:00 2001
From: Dusty Mabe <dusty@dustymabe.com>
Date: Aug 12 2019 12:07:31 +0000
Subject: [PATCH 2/3] print out a url to the issue that was created


This should help when following along in the logs.

Signed-off-by: Dusty Mabe <dusty@dustymabe.com>

---

diff --git a/compose_tracker.py b/compose_tracker.py
index 897e27d..cabf422 100755
--- a/compose_tracker.py
+++ b/compose_tracker.py
@@ -200,7 +200,11 @@ class Consumer(object):
         # Should be able to do this now https://pagure.io/libpagure/issue/31
 
         if self.token:
-            self.gitproject.create_issue(title=title, body=content)
+            issue = self.gitproject.create_issue(title=title, body=content)
+            url = issue.url.replace('/api/0/','') # have to pull the api/0 part out
+                                                  # https://github.com/packit-service/ogr/issues/146
+            logger.info(f'Opened issue: {url}')
+
 
 # The code in this file is expected to be run through fedora messaging
 # However, you can run the script directly for testing purposes. The

From a16dcb26c434ebaca793a6d5906c8e0e092e46c9 Mon Sep 17 00:00:00 2001
From: Dusty Mabe <dusty@dustymabe.com>
Date: Aug 12 2019 12:07:31 +0000
Subject: [PATCH 3/3] update issue URL for when we can add labels


- switch to calling them labels
- update to the issue in ogr that tracks being
  able to add labels to a pagure issue

Signed-off-by: Dusty Mabe <dusty@dustymabe.com>

---

diff --git a/compose_tracker.py b/compose_tracker.py
index cabf422..f662dbc 100755
--- a/compose_tracker.py
+++ b/compose_tracker.py
@@ -194,10 +194,10 @@ class Consumer(object):
 
         logger.debug(content)
 
-        # pull only part of the compose ID for the tag to set
-        tag = re.search('(.*)-\d{8}', msg['compose_id']).group(1)
-        #TODO figure out how to set tag on an issue
-        # Should be able to do this now https://pagure.io/libpagure/issue/31
+        # pull only part of the compose ID for the label to set
+        label = re.search('(.*)-\d{8}', msg['compose_id']).group(1)
+        #TODO set labels on issues when functionality is in ogr
+        # https://github.com/packit-service/ogr/issues/147
 
         if self.token:
             issue = self.gitproject.create_issue(title=title, body=content)

