Page MenuHomePhabricator

Get anchors from API instead of screen scraping
Closed, ResolvedPublic

Description

Upstream bug: https://secure.phabricator.com/T6494

We need a method in the API to get the comment anchor for a given Maniphest transaction, probably through the maniphest.gettasktransactions method. We're currently screenscraping to get this information, which is non-ideal.

Event Timeline

valhallasw raised the priority of this task from to Needs Triage.
valhallasw updated the task description. (Show Details)
valhallasw added a project: Wikibugs.
valhallasw changed Security from none to None.
valhallasw subscribed.
valhallasw changed the task status from Open to Stalled.Nov 10 2014, 7:08 PM

This needs a large change in the phabricator backend (see upstream bug), so we might need to keep scraping for a while.

Aklapper changed the task status from Stalled to Open.Mar 22 2020, 10:22 PM
Aklapper subscribed.

Upstream bug has been resolved in https://secure.phabricator.com/T5873 hence resetting task status

maniphest.gettasktransactions does seem to return the needed data currently. The endpoint takes a list of numeric task ids as input and returns a dict of numeric task id to array of transactions data as a response. Each transaction data object includes a "transactionID" member that is also the page anchor for the rendered transaction. As an example, the comment at T357449#9540635 has this data in the task transaction response:

{
      "taskID": "357449",
      "title": "Dzahn added a comment.",
      "transactionID": "9540635",
      "transactionPHID": "PHID-XACT-TASK-ftgzjmauz5vmgns",
      "transactionType": "core:comment",
      "oldValue": null,
      "newValue": null,
      "meta": {
        "remarkup.control": [],
        "core.groupID": "ln7rbtl2z53kkulyyzw3idcvppjny67g"
      },
      "comments": "The host should be usable now:\n\n```\n[ncmonitor1001:~] $ uptime\n 00:15:21 up 1 min,  1 user,  load average: 0.15, 0.04, 0.01\n[ncmonitor1001:~] $ lsb_release -c\nNo LSB modules are available.\nCodename:\tbookworm\n\n```",
      "authorPHID": "PHID-USER-fo56wm4wxiwpoofn2xdu",
      "dateCreated": "1707869805"
    }

Not all transactionID values in the returned data are actually used as anchors within the rendered task's HTML. This seems likely to vary based on the transactionType value.

bd808 changed the task status from Open to In Progress.Feb 18 2024, 4:19 AM
bd808 claimed this task.
bd808 moved this task from Ready to Go to Doing on the Wikibugs board.

Change 1004317 had a related patch set uploaded (by BryanDavis; author: Bryan Davis):

[labs/tools/wikibugs2@master] wikibugs: Get anchors from API instead of screen scraping

https://gerrit.wikimedia.org/r/1004317

Not all transactionID values in the returned data are actually used as anchors within the rendered task's HTML. This seems likely to vary based on the transactionType value.

I haven't been able to spot where in the code Phorge picks the transaction from a transaction group to use as the anchor yet. It would be excellent to discover the internal logic. During code review @valhallasw noticed that our test based on the transaction group at T218788#5041358 was incorrectly picking the anchor "5041357" from a core:subtype transaction. That same group contains:

  • "5041355" of type core:subscribers (already ignored)
  • "5041356" id of type core:columns (already ignored)
  • "5041358" id of type priority (correct per rendered HTML)
{
      "taskID": "218788",
      "title": "MusikAnimal added a comment.",
      "transactionID": "5041360",
      "transactionPHID": "PHID-XACT-TASK-ycgbldlf7reidrj",
      "transactionType": "core:comment",
      "oldValue": null,
      "newValue": null,
      "meta": [],
      "comments": "Likely related T201659",
      "authorPHID": "PHID-USER-jcbfmubdgevrfmxvfrfj",
      "dateCreated": "1553110917"
    },
    {
      "taskID": "218788",
      "title": "MusikAnimal added an edge: T201659: Pie chart does not match data.",
      "transactionID": "5041359",
      "transactionPHID": "PHID-XACT-TASK-ndjgytx3rdpzdcn",
      "transactionType": "core:edge",
      "oldValue": [],
      "newValue": [
        "PHID-TASK-3u4xrqafari4teub64ir"
      ],
      "meta": {
        "edge:type": 52
      },
      "comments": null,
      "authorPHID": "PHID-USER-jcbfmubdgevrfmxvfrfj",
      "dateCreated": "1553110917"
    },
    {
      "taskID": "218788",
      "title": "MusikAnimal triaged this task as \"Medium\" priority.",
      "transactionID": "5041358",
      "transactionPHID": "PHID-XACT-TASK-w5akmjtqbn7sbcn",
      "transactionType": "priority",
      "oldValue": "90",
      "newValue": "50",
      "meta": [],
      "comments": null,
      "authorPHID": "PHID-USER-jcbfmubdgevrfmxvfrfj",
      "dateCreated": "1553110917"
    },
    {
      "taskID": "218788",
      "title": "MusikAnimal changed the subtype of this task from \"Task\" to \"Bug Report\".",
      "transactionID": "5041357",
      "transactionPHID": "PHID-XACT-TASK-fzusuy7dn6eile4",
      "transactionType": "core:subtype",
      "oldValue": "default",
      "newValue": "bug",
      "meta": [],
      "comments": null,
      "authorPHID": "PHID-USER-jcbfmubdgevrfmxvfrfj",
      "dateCreated": "1553110917"
    },
    {
      "taskID": "218788",
      "title": "MusikAnimal moved this task from Backlog to Page History on the XTools board.",
      "transactionID": "5041356",
      "transactionPHID": "PHID-XACT-TASK-on6c7ic6w5ekxwb",
      "transactionType": "core:columns",
      "oldValue": null,
      "newValue": [
        {
          "columnPHID": "PHID-PCOL-gbevbd2r45q2mnwcb7kl",
          "boardPHID": "PHID-PROJ-nqutcmxajqx6dmsju33t",
          "fromColumnPHIDs": {
            "PHID-PCOL-vsl3k7okjxj4ctlq4ezg": "PHID-PCOL-vsl3k7okjxj4ctlq4ezg"
          }
        }
      ],
      "meta": [],
      "comments": null,
      "authorPHID": "PHID-USER-jcbfmubdgevrfmxvfrfj",
      "dateCreated": "1553110917"
    },
    {
      "taskID": "218788",
      "title": "MusikAnimal added a subscriber: MusikAnimal.",
      "transactionID": "5041355",
      "transactionPHID": "PHID-XACT-TASK-po5xkitkkhdjoij",
      "transactionType": "core:subscribers",
      "oldValue": [
        "PHID-USER-t3nv7yezg2e6z6yeqrob"
      ],
      "newValue": [
        "PHID-USER-t3nv7yezg2e6z6yeqrob",
        "PHID-USER-jcbfmubdgevrfmxvfrfj"
      ],
      "meta": [],
      "comments": null,
      "authorPHID": "PHID-USER-jcbfmubdgevrfmxvfrfj",
      "dateCreated": "1553110917"
    },

My current hypothesis is that if we ignore the correct set of types things will work as hoped. This is all guess work at the moment however.

Change 1004317 merged by jenkins-bot:

[labs/tools/wikibugs2@master] wikibugs: Get anchors from API instead of screen scraping

https://gerrit.wikimedia.org/r/1004317

Mentioned in SAL (#wikimedia-cloud) [2024-02-27T20:45:50Z] <wmbot~bd808@tools-sgebastion-11> Restarted wikibugs-phab job to pick up fixes for T1175, T1176, and T1177

This is implemented and deployed. I'm not sure that we won't walk the change back because of the lack of a clear algorithm for selecting which transaction id is used as an anchor in the Phorge html, but let's see how it goes.