Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

Add API action 'findwikis' to find a wiki by a change number #537

Merged
merged 2 commits into from
Mar 22, 2023
Merged

Conversation

edg2s
Copy link
Collaborator

@edg2s edg2s commented Mar 20, 2023

Part of #285

@edg2s
Copy link
Collaborator Author

edg2s commented Mar 20, 2023

Example request/response:
https://patchdemo.wmflabs.org/api.php?action=findwikis&change=813350

[
  {
    "wiki":"0483bb0894",
    "creator":"ESanders (WMF)",
    "created":"2022-07-13 15:11:52",
    "url":"https:\/\/patchdemo.wmflabs.org\/wikis\/0483bb0894\/wiki\/Special:UserLogin?returnto=Talk%3ADiscussionTools"
  },
  {
    "wiki":"2ca64449dd",
    "creator":"ESanders (WMF)",
    "created":"2022-07-13 15:13:23",
    "url":"https:\/\/patchdemo.wmflabs.org\/wikis\/2ca64449dd\/wiki\/Special:UserLogin?returnto=Talk%3ADiscussionTools"
  }
]

@edg2s
Copy link
Collaborator Author

edg2s commented Mar 20, 2023

cc @hashar

@hashar
Copy link
Contributor

hashar commented Mar 20, 2023

Nice! Maybe the url should be unescaped in the json response?

If a change has multiple wikis, maybe we would need the list of applied patches to help disambiguates between multiple instances similar to how it is displayed on https://patchdemo.wmflabs.org/

@edg2s
Copy link
Collaborator Author

edg2s commented Mar 20, 2023

It's much more common that wikis get rebuilt the same set of changes, but just newer patchsets.

@edg2s
Copy link
Collaborator Author

edg2s commented Mar 20, 2023

Maybe the url should be unescaped in the json response?

This is just PHPs default JSON encoding...

php > echo json_encode("a/b");
"a\/b"

@edg2s
Copy link
Collaborator Author

edg2s commented Mar 20, 2023

I've added patch data to the response:

[
  {
    "wiki":"0483bb0894",
    "creator":"Ed",
    "created":"2022-07-13 15:11:52",
    "patches":[
      "813350,2"
    ],
    "url":"http:\/\/localhost\/patchdemo\/wikis\/0483bb0894\/wiki\/Special:UserLogin?returnto=Talk%3ADiscussionTools"
  },
  {
    "wiki":"2ca64449dd",
    "creator":"Ed",
    "created":"2022-07-13 15:13:23",
    "patches":[
      "813350,2"
    ],
    "url":"http:\/\/localhost\/patchdemo\/wikis\/2ca64449dd\/wiki\/Special:UserLogin?returnto=Talk%3ADiscussionTools"
  }
]

@edg2s
Copy link
Collaborator Author

edg2s commented Mar 20, 2023

Maybe the url should be unescaped in the json response?

This is just PHPs default JSON encoding...

php > echo json_encode("a/b");
"a\/b"

Apparently there's a flag for this: #541

@hashar
Copy link
Contributor

hashar commented Mar 20, 2023

php > echo json_encode("a/b");
"a\/b"

I am so PHP illiterate nowadays ;)

To disambiguate, I think the instances can be represented with the wiki ids followed by either the change number or task (whatever set has the least items):

Run Summary
Patchdemo ↗️ 0483bb0894 T123456
Patchdemo ↗️ 2ca64449dd 888333,43

Then clicking on one of the line would expand a drop down with some raw text giving more details. There for a single task and multiple patches:

Patch demo ↗️ 0483bb0894  `T123456`

993049,39 (merged) Do some stuff
993012,13 Some other things

And a single Gerrit change referring to multiple tasks:

Patch demo ↗️ 2ca64449dd   `888333,43`

T304943 Fix up foo
🗸T309098 Adjust compatibility for Y
T309099 Adjust compatibility for Z

Given the dropdown message is a raw text unfortunately, but that at least gives some informations :)

@edg2s
Copy link
Collaborator Author

edg2s commented Mar 20, 2023

As above, I don't think this will disambiguate in most cases (also we take the task number from the gerrit description, so there's no new info there). You'd be better off showing the patchset number it was built for on this change, followed by the timestamp:

Run Summary
Patchdemo ↗️ 0483bb0894 PS3, 4 days ago
Patchdemo ↗️ 2ca64449dd PS4, 2 hours ago
Patchdemo ↗️ 449dd2ca64 PS4, 10 minutes ago

@hashar
Copy link
Contributor

hashar commented Mar 20, 2023

Sounds good :)

@edg2s edg2s requested a review from MatmaRex March 22, 2023 18:38
@MatmaRex MatmaRex merged commit 93a0314 into api Mar 22, 2023
@MatmaRex MatmaRex deleted the findwikis branch March 22, 2023 23:08
@edg2s
Copy link
Collaborator Author

edg2s commented Mar 23, 2023

@hashar this as been deployed

@hashar
Copy link
Contributor

hashar commented May 23, 2023

In case someone come here in the future, there are some screenshots of the integration in Gerrit at https://phabricator.wikimedia.org/T332474#8874936

wmfgerrit pushed a commit to wikimedia/operations-software-gerrit that referenced this pull request May 24, 2023
Patch demo requested a Gerrit integration to show wikis spawned for a
given change. Following discussions on T332474, they have implemented a
`findwikis` action API: MatmaRex/patchdemo#537

Example:

https://patchdemo.wmflabs.org/api.php?action=findwikis&change=822099
 [
   {
     "wiki": "a442d4db80",
     "creator": "ESanders (WMF)",
     "created": "2022-08-10 22:08:38",
     "patches": [
       "822099,3",
       "820233,6"
     ],
     "url": "https://patchdemo.wmflabs.org/wikis/a442d4db80/w"
   },
   ...
 ]

Which should be represented as a check result:

 | Patchdemo | ↗️  a442d4db80 PS3, X time ago

Bug: T332474
Change-Id: I00199133eaaf5ff59a3b563c335eefaffb1ff4fb
@hashar hashar mentioned this pull request May 24, 2023
edg2s pushed a commit that referenced this pull request May 24, 2023
We need the API to emit `Access-Control-Allow-Origin: *` to allow
downstream usage in JavaScript application. For example the integration
with https://gerrit.wikimedia.org/. Without it, the browser complains
with:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading
the remote resource at
https://patchdemo.wmflabs.org/api.php?action=findwikis&change=922162.
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

Part of #285
Follow-up #537

Bug: https://phabricator.wikimedia.org/T332474
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants