#282 Sync proposals done through the app instantly
Opened 3 months ago by frantisekz. Modified 3 months ago

@@ -27,8 +27,8 @@ 

  import json

  import itertools

  

- from blockerbugs import app, __version__

- from blockerbugs.util import bz_interface, pagure_bot, misc

+ from blockerbugs import app, db, __version__

+ from blockerbugs.util import bz_interface, pagure_bot, misc, discussion_sync, bug_sync

  from blockerbugs.models.bug import Bug

  from blockerbugs.models.milestone import Milestone

  from blockerbugs.models.update import Update
@@ -443,6 +443,16 @@ 

  

      return bz_interface.create_bugzilla()

  

+ def bugzilla_sync_proposal(bugid, milestone, blocker, fe):

+     # Fetch the proposed stuff into the database right away

+     sync = bug_sync.BugSync(db)

+     trackers_str = []

+     if blocker: trackers_str.append("Blocker")

+     if fe:      trackers_str.append("FreezeException")

+     sync.fetch_single_bug(milestone, bugid, trackers_str)

+ 

+     # Create a discussion ticket

+     discussion_sync.create_discussions_links(milestone, [misc.bug_from_db(bugid, milestone)])

  

  @main.route('/propose_bug', methods=['GET', 'POST'])

  @fas_login_required
@@ -500,6 +510,7 @@ 

                  user, bugid, proposal.get_tracker_type(), selected_milestone.name))

              try:

                  proposal.propose_bugs(user, selected_milestone.name, bugform.justification.data)

+                 bugzilla_sync_proposal(bugid, selected_milestone, bool(bugform.blocker.data), bool(bugform.freeze_exception.data))

                  return render_template('thanks.html', bugid=bugid,

                                         isblocker=bugform.blocker.data,

                                         isfe=bugform.freeze_exception.data,

@@ -150,6 +150,22 @@ 

  

          self.db.session.commit()

  

+     def fetch_single_bug(self, milestone: Milestone, bugid, trackers) -> None:

+         self.log.info("Fetching bug data for %s" % bugid)

+         bug = self.bzinterface.bz.getbug(bugid)

+         oldbug = Bug.query.filter_by(bugid=bug.bug_id, milestone=milestone).first()

+ 

+         for tracker in trackers:

+             buginfo = self.extract_information(bug, tracker)

+             if oldbug:

+                 oldbug.update(buginfo, tracker, milestone)

+                 self.db.session.add(oldbug)

+             else:

+                 newbug = Bug.from_data(buginfo, milestone, tracker)

+                 self.db.session.add(newbug)

+ 

+         self.db.session.commit()

+ 

      def cleanup_milestone(self, milestone: Milestone, tracker_type: str) -> None:

          """'Clean up' all bugs under `tracker_type` in `milestone`, which are not currently blocking

          the relevant tracker ticket. Cleaning up means setting all those bugs as rejected

@@ -2,7 +2,7 @@ 

  

  from blockerbugs import db, app

  from blockerbugs.config import Config as bb_Config

- from blockerbugs.util import pagure_interface

+ from blockerbugs.util import pagure_interface, bz_interface

  from blockerbugs.models.milestone import Milestone

  from blockerbugs.models.release import Release

  from blockerbugs.models.bug import Bug

file modified
+4 -1
@@ -3,7 +3,7 @@ 

  from typing import Optional

  

  from blockerbugs import _version

- 

+ from blockerbugs.models.bug import Bug

  

  def version_date() -> Optional[str]:

      """Return the date (just the date portion) of the app version identifier, as returned by
@@ -15,3 +15,6 @@ 

      parts = date.split(sep='T')

      assert len(parts) == 2

      return parts[0]

+ 

+ def bug_from_db(bugid, milestone):

+     return Bug.query.filter_by(bugid=bugid, milestone=milestone).first()