#4703 Expose related_prs on issue API
Merged a year ago by pingou. Opened a year ago by lenkaseg.
lenkaseg/pagure related_prs  into  master

file modified
+5
@@ -1483,6 +1483,11 @@ 

              "closed_by": self.closed_by.to_json(public=public)

              if self.closed_by

              else None,

+             "related_prs": [

+                 {"id": pr.id, "title": pr.title} for pr in self.related_prs

+             ]

+             if self.related_prs

+             else [],

          }

  

          comments = []

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

      issue_id=None,

      issue_uid=None,

      private=False,

+     related_prs=[],

      status=None,

      close_status=None,

      notify=True,

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

          "milestone": None,

          "priority": None,

          "private": True,

+         "related_prs": [],

          "status": "Closed",

          "tags": [],

          "title": "Test issue",
@@ -70,6 +71,7 @@ 

          "milestone": None,

          "priority": None,

          "private": True,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "test issue1",
@@ -91,6 +93,7 @@ 

          "milestone": None,

          "priority": None,

          "private": True,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "test issue",
@@ -112,6 +115,7 @@ 

          "milestone": None,

          "priority": None,

          "private": False,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "test issue",
@@ -133,6 +137,7 @@ 

          "milestone": None,

          "priority": None,

          "private": False,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "test issue",
@@ -154,6 +159,7 @@ 

          "milestone": None,

          "priority": None,

          "private": False,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "test issue",
@@ -175,6 +181,7 @@ 

          "milestone": None,

          "priority": None,

          "private": False,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "test issue",
@@ -196,6 +203,7 @@ 

          "milestone": "milestone-1.0",

          "priority": None,

          "private": False,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "test issue",
@@ -217,6 +225,7 @@ 

          "milestone": None,

          "priority": None,

          "private": False,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "test issue",
@@ -242,6 +251,7 @@ 

          "milestone": None,

          "priority": None,

          "private": False,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "Issue #2",
@@ -263,6 +273,7 @@ 

          "milestone": None,

          "priority": None,

          "private": False,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "Issue #1",
@@ -2482,6 +2493,7 @@ 

                          "milestone": None,

                          "priority": None,

                          "private": True,

+                         "related_prs": [],

                          "status": "Open",

                          "tags": [],

                          "title": "Issue #3",
@@ -2545,6 +2557,7 @@ 

                  "milestone": None,

                  "priority": None,

                  "private": False,

+                 "related_prs": [],

                  "status": "Open",

                  "tags": [],

                  "title": "test issue",
@@ -2644,6 +2657,7 @@ 

                  "milestone": None,

                  "priority": None,

                  "private": True,

+                 "related_prs": [],

                  "status": "Open",

                  "tags": [],

                  "title": "Test issue",
@@ -2675,6 +2689,7 @@ 

                  "milestone": None,

                  "priority": None,

                  "private": True,

+                 "related_prs": [],

                  "status": "Open",

                  "tags": [],

                  "title": "Test issue",
@@ -3155,6 +3170,60 @@ 

          data = json.loads(output.get_data(as_text=True))

          self.assertDictEqual(data, {"error": "error", "error_code": "ENOCODE"})

  

+     def test_api_view_issue_related_prs(self):

+         tests.create_projects(self.session)

+         tests.create_projects_git(os.path.join(self.path, "tickets"))

+         tests.create_tokens(self.session)

+         tests.create_tokens_acl(self.session)

+ 

+         # Create issue

+         repo = pagure.lib.query.get_authorized_project(self.session, "test")

+         msg = pagure.lib.query.new_issue(

+             session=self.session,

+             repo=repo,

+             title="Test issue #1",

+             content="We should work on this",

+             user="pingou",

+             private=False,

+             issue_uid="aaabbbccc1",

+         )

+         self.session.commit()

+         self.assertEqual(msg.title, "Test issue #1")

+         self.assertEqual(msg.related_prs, [])

+         self.assertEqual(msg.id, 1)

+ 

+         # Create pull request

+         repo_to = pagure.lib.query.get_authorized_project(self.session, "test")

+         repo_from = pagure.lib.query.get_authorized_project(

+             self.session, "test"

+         )

+ 

+         msg = pagure.lib.query.new_pull_request(

+             session=self.session,

+             repo_from=repo_from,

+             repo_to=repo_to,

+             branch_from="master",

+             branch_to="master",

+             title="New shiny feature",

+             user="pingou",

+             initial_comment="Fixes #1",

+         )

+         self.session.commit()

+         self.assertEqual(msg.id, 2)

+         self.assertEqual(msg.title, "New shiny feature")

+ 

+         output = self.app.get("/api/0/test/pull-request/2")

+         self.assertEqual(

+             json.loads(output.get_data(as_text=True)).get("initial_comment"),

+             "Fixes #1",

+         )

+ 

+         output = self.app.get("/api/0/test/issue/1")

+         data = json.loads(output.get_data(as_text=True))

+         self.assertEqual(

+             data.get("related_prs"), [{"id": 2, "title": "New shiny feature"}]

+         )

+ 

      @patch("pagure.lib.git.update_git")

      @patch("pagure.lib.notify.send_email")

      def test_api_view_issue_comment(self, p_send_email, p_ugt):

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

                      "milestone": None,

                      "priority": None,

                      "private": False,

+                     "related_prs": [],

                      "status": "Open",

                      "tags": [],

                      "title": "test issue",
@@ -207,6 +208,7 @@ 

                      "milestone": None,

                      "priority": None,

                      "private": False,

+                     "related_prs": [],

                      "status": "Open",

                      "tags": [],

                      "title": "test issue",
@@ -258,6 +260,7 @@ 

                      "milestone": None,

                      "priority": None,

                      "private": False,

+                     "related_prs": [],

                      "status": "Open",

                      "tags": [],

                      "title": "test issue",

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

          "milestone": None,

          "priority": None,

          "private": True,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "Test issue",
@@ -59,6 +60,7 @@ 

          "milestone": None,

          "priority": None,

          "private": True,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "test issue",
@@ -80,6 +82,7 @@ 

          "milestone": None,

          "priority": None,

          "private": True,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "test issue",
@@ -101,6 +104,7 @@ 

          "milestone": None,

          "priority": None,

          "private": False,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "test issue",
@@ -122,6 +126,7 @@ 

          "milestone": None,

          "priority": None,

          "private": False,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "test issue",
@@ -143,6 +148,7 @@ 

          "milestone": None,

          "priority": None,

          "private": False,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "test issue",
@@ -164,6 +170,7 @@ 

          "milestone": None,

          "priority": None,

          "private": False,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "test issue",
@@ -185,6 +192,7 @@ 

          "milestone": None,

          "priority": None,

          "private": False,

+         "related_prs": [],

          "status": "Open",

          "tags": [],

          "title": "test issue",
@@ -2477,6 +2485,7 @@ 

                              "milestone": None,

                              "priority": None,

                              "private": False,

+                             "related_prs": [],

                              "status": "Open",

                              "tags": [],

                              "title": "test issue",
@@ -2553,6 +2562,7 @@ 

                              "milestone": None,

                              "priority": None,

                              "private": True,

+                             "related_prs": [],

                              "status": "Open",

                              "tags": [],

                              "title": "Test issue",
@@ -2574,6 +2584,7 @@ 

                              "milestone": None,

                              "priority": None,

                              "private": False,

+                             "related_prs": [],

                              "status": "Open",

                              "tags": [],

                              "title": "test issue",
@@ -2643,6 +2654,7 @@ 

                          "milestone": None,

                          "priority": None,

                          "private": True,

+                         "related_prs": [],

                          "status": "Open",

                          "tags": [],

                          "title": "Test issue",
@@ -2664,6 +2676,7 @@ 

                          "milestone": None,

                          "priority": None,

                          "private": False,

+                         "related_prs": [],

                          "status": "Open",

                          "tags": [],

                          "title": "test issue",
@@ -2804,6 +2817,7 @@ 

                          "milestone": None,

                          "priority": None,

                          "private": True,

+                         "related_prs": [],

                          "status": "Open",

                          "tags": [],

                          "title": "Test issue",
@@ -2825,6 +2839,7 @@ 

                          "milestone": None,

                          "priority": None,

                          "private": False,

+                         "related_prs": [],

                          "status": "Open",

                          "tags": [],

                          "title": "test issue",
@@ -2901,6 +2916,7 @@ 

                      "milestone": None,

                      "priority": None,

                      "private": False,

+                     "related_prs": [],

                      "status": "Open",

                      "tags": [],

                      "title": "test issue",
@@ -2949,6 +2965,7 @@ 

                  "milestone": None,

                  "priority": None,

                  "private": False,

+                 "related_prs": [],

                  "status": "Open",

                  "tags": [],

                  "title": "test issue",

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

                              "url_path": "test",

                              "user": {"fullname": "PY C", "name": "pingou"},

                          },

+                         "related_prs": [],

                          "status": "Open",

                          "tags": [],

                          "title": "Test issue",

file modified
+2 -1
@@ -1411,7 +1411,7 @@ 

  index 0000000..60f7480

  --- /dev/null

  +++ b/456

- @@ -0,0 +1,29 @@

+ @@ -0,0 +1,30 @@

  +{

  +    "assignee": null,

  +    "blocks": [],
@@ -1427,6 +1427,7 @@ 

  +    "milestone": null,

  +    "priority": null,

  +    "private": false,

+ +    "related_prs": [],

  +    "status": "Open",

  +    "tags": [],

  +    "title": "Test issue",

Related PRs exposed in API, shows as related_prs in: https://pagure.io/api/0/<repo>/issue/<issueid>

Fixes: #4546

It looks like this

rebased onto 677a665ff189806c7a68b8f3b180e4d65e114865

a year ago

Pretty please pagure-ci rebuild

Test failure...

20:52:07  FAILED test: py3-test_pagure_flask_api_issue
20:52:07  FAILED test: py3-test_pagure_flask_api_issue_create
20:52:07  FAILED test: py3-test_pagure_flask_api_ui_private_repo
20:52:07  FAILED test: py3-test_pagure_flask_api_user
20:52:07  FAILED test: py3-test_pagure_lib_git

I see...
I'll fix the tests.

pretty please pagure-ci rebuild

a year ago

should not all those "related_prs": null, on test be None instead of null ?

I think so. I'm sorry, I hope I'll find some time today to fix it. Should I add a test case for it?

In my environment only 1 test seems to be failing, this one: test_pagure_flask_api_user

In my environment only 1 test seems to be failing, this one: test_pagure_flask_api_user

running a ci job on a different pr to discard|detect pipeline issues: https://ci.centos.org/job/pagure-pr/3052/

Indeed, something is up with the pipeline. job 3052 has not any code change from previous passed runs

rebased onto 73aedb9a5a3c5638832690ff241fc39f6d6c7435

a year ago

Should we default to an empty list instead of None?

Might be good to add a test where the field isn't None or [] :)

rebased onto cc2deab8f815969aad43bdbef29ede99a4c3a691

a year ago

Should we default to an empty list instead of None?

OK

Might be good to add a test where the field isn't None or [] :)

Ok, I'll add a test case :)

Should we default to an empty list instead of None?

that would be easier to consume for api users

rebased onto 7edfb239b606810d0f15e41976d834f01ce77a48

a year ago

pretty please pagure-ci rebuild

a year ago

pretty please pagure-ci rebuild

a year ago

rebased onto a091299f85e846c5155741c8d1f9e8ef24b8db29

a year ago

Failing tests:

14:45:58  Failed tests:
14:45:58  FAILED test: py3-test_pagure_flask_api_issue
14:45:58  FAILED test: py3-test_pagure_flask_api_issue_create
14:45:58  FAILED test: py3-test_pagure_flask_api_ui_private_repo
14:45:58  FAILED test: py3-test_pagure_flask_api_user
14:45:58  FAILED test: py3-test_pagure_lib_git

@lenkaseg could I bump this PR? We are hoping to use this feature in an enchantment for a service! :)

Thank you for the work on this PR. I'm looking forward to this capability.

Would it be possible to also add the inverse relationship? i.e. Return the list of related issues when querying a PR through GET /api/0/fork/<username>/<repo>/pull-request/<request id>

Sorry people for letting it hang for so long time. I've been very busy. I'm planning to finish this PR over the weekend. If I don't, feel free to take it.

rebased onto af788a64d7f88d281baf985f6034fcccad998757

a year ago

pretty please pagure-ci rebuild

a year ago

rebased onto d7ca5aa5dbcc8252dbedb10b477e72d7d14303f3

a year ago

rebased onto 49621bb4af4c8714ac53ab588b880be684360f0c

a year ago

rebased onto 3bcab89fc288aa102a8477b31f5f11f2cf86af52

a year ago

rebased onto e66a89bcae8b08c8a680feea1230a8c776a09d1a

a year ago

rebased onto ff538d3d38d6a6a51386ece4cb08778257753df3

a year ago

rebased onto 4b3eeba82829afb721adbe2353cd2453bb9a0f0e

a year ago

Thank you for the work on this PR. I'm looking forward to this capability.
Would it be possible to also add the inverse relationship? i.e. Return the list of related issues when querying a PR through GET /api/0/fork/<username>/<repo>/pull-request/<request id="">

I'll take a shot at it :)

I don't think there is anything to commit at this point :)

One nit-pick otherwise looks good :)

I don't think there is anything to commit at this point :)

Yes, I see, it's twice there :)

rebased onto 57a704d9c9213a3ca669ba3864c974c61be6252f

a year ago

rebased onto 3871071

a year ago

pretty please pagure-ci rebuild

a year ago

Pull-Request has been merged by pingou

a year ago

Thank you for the work on this PR. I'm looking forward to this capability.
Would it be possible to also add the inverse relationship? i.e. Return the list of related issues when querying a PR through GET /api/0/fork/<username>/<repo>/pull-request/<request id="">

I'll take a shot at it :)

Hey, @lenkaseg thanks for implementing this! I was wondering if you were able to get the above feature working? (i.e. looking for related issues through pull requests)

Hey @lenkaseg I just wanted to bump this again. Thanks!

@sidpremkumar Sorry, I didn't see the message. I'll try to fix it for the pull requests too. Or you already did?

@lenkaseg I have not done it, it would be awesome if this could be added!

@sidpremkumar Ok! Let's see if I find some time during the weekend :)

@sidpremkumar Sorry, I have no time lately :( But I you want to do it, I can do review.

@lenkaseg not a problem, not critical need for us, so whenever it gets done (if) is okay :) Thanks for following up though!

Metadata