Page MenuHomePhabricator

Gather data how much code development activity takes place canonically in Phabricator Diffusion
Closed, ResolvedPublic

Description

This task is a followup to T212904: Create a Tech Contributors Map to document major audiences and their goals.
This task is related to T237470: Create and maintain a list of organization repos that are maintained on Gerrit, GitHub, and Diffusion when it comes to the "Diffusion" part in its task summary.

We seem to have >300 repositories which use Phabricator Diffusion as a canonical place. As far as I know, we do not have stats how much development activity happens in these repos.

First question is probably: How to differentiate which commits were not "imported" but are canonical in Diffusion?

Event Timeline

• Aklapper triaged this task as Low priority.

Have not taken a really close look, so just dropping stuff here:

The isImporting attribute seems to about active imports, not mirroring. The wording on the conduit API page is not clear, but listing all of the repos where this flag is false is a random grab bag of repos.

$ python3 diffusion_stats.py
extension-Athena
extension-Survey
MediaWiki Extensions
extension-ApprovedRevs
extension-Flow
wikimedia-cz-tracker
extension-JsonConfig
extension-LdapAuthentication
MediaWiki
extension-Html2Wiki
extension-GWToolset
extension-ReadingLists
extension-Newsletter
extension-TimedMediaHandler
education-program-dashboard
extension-WikimediaMaintenance
extension-Collection
extension-LiquidThreads
extension-Scribunto
integration-config
extension-Jade
mediawiki-services-mobileapps
CirrusSearch
extension-Duplicator
extension-TwitterLogin
analytics-quarry-web
Gerrit Code Review
labs-tools-wikibugs2
mediawiki/oauthclient-php
extension-WikiSEO
Wikimedia Puppet
extension-Genealogy
extension-AnonPrivacy
extension-Cognate
tool-libraryupgrader
labs/libraryupgrader
translatewiki
labs-tools-shorturls
tool-reviewers
tool-phpcs
tool-newusers
tool-ldap
tool-mwpackages
operations-software
extension-WikiLove
extension-GlobalCssJs
labs-tools-watch-translations
labs-tools-commons-mass-description
operations-software-tools-webservice
The official Wikipedia iOS application
tool-xtools
wikidata-query-gui
wikipedia-gadgets-ProveIt
Phabricator Translations
VisualEditor
Huggle
extension-DataTransfer
extension-Drafts
labs-tool-extdist
extension-RegexBlock
extensions-Mailgun
extension-GeoData
extension-EditSimilar
extension-Cargo
extension-Wikibase
extension-LogEntry
extension-AbsenteeLandlord
mediawiki/extensions/WikidataPageBanner
extension-WikimediaEvents
extension-TranslateSvg
extension-AdminLinks
extension-SimpleSAMLphp
extension-UserPageViewTracker
extension-PagedTiffHandler
extension-NSFileRepo
extension-MultiLanguageManager
extension-Math
extension-MachineVision
extension-Lingo
extension-LDAPGroups
extension-ActiveAbstract
extension-UserAgreement
extension-MarkAsHelpful
extension-BlueSpiceVisualDiff
extension-SocialLogin
extension-Cite
extension-QuizGame
extension-MintyDocs
extension-NewUserMessage
extension-Interwiki
labs-tools-bookreader
extension-CollaborationKit
labs-private
cloud-instance-puppet
extension-GoogleAuthenticator
extension-Calendar
extension-GettingStarted
extension-LifeWeb
extension-Examples
extension-PageTriage
diffusion_stats.py
import phabricator


phab = phabricator.Phabricator(
    host="https://phabricator.wikimedia.org/api/",
    token="<PUT YOUR API KEY HERE>",
)
phab.update_interfaces()

for r in phab.diffusion.repository.search(queryKey="active")["data"]:
    if not r["fields"]["isImporting"]:
        print(r["fields"]["name"])

Wondering if @mmodell has any idea how to approach this (UI or API wise) when it comes to finding which code repos are canonical in Diffusion (I guess/hope I'll find out pulling the latest changes and their authors myself). If not, that is totally fine too. Just worth a shot I thought, before I spend more time on this.

Phabricator repos have associated URIs which can be set to "observe" .. Any repo without an observe url is "hosted in diffusion." The diffusion.repository.search api supports the "uris" attachment.

So what you'd need to do is query the repository.search api and pass { "attachments": { "uris": true } } and then look for the URI with io set to "observe"

Here's an example of the api response:

{
  "result": {
    "data": [

      {
      "id": 459,
      "type": "REPO",
      "phid": "PHID-REPO-...",
      "fields": {
        "name": "extension-Quiz",
        "vcs": "git",
        "callsign": "EQUI",
        "shortName": null,
        "status": "active",
        "isImporting": false,
        "almanacServicePHID": null,
        "refRules": {
          "fetchRules": [],
          "trackRules": [],
          "permanentRefRules": []
        },
        "defaultBranch": "master",
        "description": {
          "raw": "MediaWiki extension Quiz"
        },
        "spacePHID": null,
        "dateCreated": 1417810068,
        "dateModified": 1565042963
      },
      "attachments": {
        "uris": {
          "uris": [{
            "id": "4363",
            "type": "RURI",
            "phid": "PHID-RURI-orccdbwoccehdy7zjas3",
            "fields": {
              "repositoryPHID": "PHID-REPO-hmrzsn5mcavq3xghlp6p",
              "uri": {
                "raw": "https:\/\/gerrit-replica.wikimedia.org\/r\/mediawiki\/extensions\/Quiz",
                "display": "https:\/\/gerrit-replica.wikimedia.org\/r\/mediawiki\/extensions\/Quiz",
                "effective": "https:\/\/gerrit-replica.wikimedia.org\/r\/mediawiki\/extensions\/Quiz",
                "normalized": "gerrit-replica.wikimedia.org\/r\/mediawiki\/extensions\/Quiz"
              },
              "io": {
                "raw": "observe",
                "default": "none",
                "effective": "observe"
              },
              "display": {
                "raw": "visible",
                "default": "never",
                "effective": "visible"
              },
              "credentialPHID": null,
              "disabled": false,
              "builtin": {
                "protocol": null,
                "identifier": null
              },
              "dateCreated": "1463620767",
              "dateModified": "1565042963"
            }
          }
         ]
       }
     }

The key part is result.data.[].attachments.uris.uris.[].io.raw

Thanks for the pointers.

This does not seem to work, or I'm doing something wrong. Assuming that the raw value should not be observe,
$:acko\> echo '{ "attachments": { "uris": true } }' | /var/www/html/phab/arcanist/bin/arc call-conduit --conduit-uri https://phabricator.wikimedia.org/ --conduit-token "cli-xxxxxxxxxxxxxxx" diffusion.repository.search | jq '.response.data[] | select(.attachments.uris.uris[].fields.io.raw != "observe").fields.name'
gives me a list of some repos which are canonical in Gerrit, same when using == "observe" instead. Meh.

@Aklapper: observe is only active if the uri is enabled, so perhaps some have disabled uris set to observe.

... gives me a list of some repos which are canonical in Gerrit, same when using == "observe" instead. Meh.

I spent some time fiddling with the jq example that you posted and I think the problem is the following:

It seems that select(.attachments.uris.uris[].fields.io.raw != "observe") passes any repo that has any uri where io is something other than "observe", however, all of the repos have at least one uri that will match != "observe" so they all get included in the output of the select()`.

I may be wrong about this but that's what seems to be happening from my admittedly brief attempt at this problem. Unfortunately I don't know jq well enough to make it do the right thing without spending significantly more time at it. I might take a stab at just doing it in php or python (or even javascript) later but for now I need to work on other things.

Thanks mmodell for the pointers, and especially for that last link which is very helpful. (Still trying to turn those web UI search results into some API call.)

Some notes for myself:
Using echo '{ "attachments": { "uris": true } }' | /var/www/html/phab/arcanist/bin/arc call-conduit --conduit-uri https://phabricator.wikimedia.org/ --conduit-token "api-xxxx" diffusion.repository.search | jq '.response.data[]' and looking at that output, every repo has several subelements in attachments 🡒 uris 🡒 uris[]. Manually looking for a repo that is canonical in Diffusion, and trying to find anything special, "name": "tool-newusers" looked like a candidate. Looks like I need to check if attachments 🡒 uris 🡒 uris[] 🡒 fields 🡒 io 🡒 raw is default for the first subelement of attachments 🡒 uris 🡒 uris[]. (Others values could be none, observe or mirror for mirrored repos.)

Call: echo '{ "after":"0", "attachments": { "uris": true } }' | /var/www/html/phab/arcanist/bin/arc call-conduit --conduit-uri https://phabricator.wikimedia.org/ --conduit-token "api-xxxx" diffusion.repository.search | jq '.response.data[] | select(.attachments.uris.uris[0].fields.io.raw == "default").fields.name'

Next: Somehow iterate by setting after cursor value (because pagination limit is 100 results). Then find out how to get activity for each repo via diffusion.commit.search . Or such. Who knows. Because no clue how to find a proper "project" or "repository" value. All that I tried did not work.

It seems not to be possible to easily git clone all repos: Sometimes name is null, sometimes fullName is null, sometimes callsign is null. So there is no consistent one single way to get a list of all repos without manual fiddling.

My naive idea was to pull all repos hosted, after somehow getting the list of all repos:

  • Get names of all repos: echo '{"queryKey":"ias.VEMtSCGU"}' | /arcanist/bin/arc call-conduit diffusion.repository.search --
  • Repeat a few times to deal with pagination (max 100 results per query) a la echo '{"queryKey":"ias.VEMtSCGU","after":"123"}
  • Parse JSON to get all repo project names, then construct repo URLs to git clone
  • Then locally run git log in each repo. (Probably git cloneing isn't the best but I'm too lazy to look into diffusion.commit.search or diffusion.historyquery.)

But:

  • name can have spaces so no working checkout URL constructed. So I tried shortName but shortName is sometimes null. See previous comment here.
  • Cloning numerous repos fails with fatal: repository not found, e.g. git clone https://phabricator.wikimedia.org/source/extension-AutoCategoriseUploads.git. https://phabricator.wikimedia.org/diffusion/EACU/extension-autocategoriseuploads.git URL style works, but no idea how to find out when.
  • T271004 blocks getting a full list of repos. Manual work: Also clone what's on https://phabricator.wikimedia.org/diffusion/query/ias.VEMtSCGU/?after=1632
  • Some repos (Phab related ones) pull from upstreams: Need to manually exclude them not to get distorted development activity stats.
  • And for a few repos I don't have required permissions (but that's okay): Authentication failed

Edit: Ignore this comment.

Copy and pasting my steps as of today (as I usually don't remember anything tomorrow):

$:acko\> echo '{"queryKey":"ias.VEMtSCGU"}' | /var/www/html/phab/arcanist/bin/arc call-conduit --conduit-uri https://phabricator.wikimedia.org/ --conduit-token "api-x" diffusion.repository.search -- > foojson1
$:acko\> echo '{"queryKey":"ias.VEMtSCGU","after":"2632"}' | /var/www/html/phab/arcanist/bin/arc call-conduit --conduit-uri https://phabricator.wikimedia.org/ --conduit-token "api-x" diffusion.repository.search --  > foojson2
$:acko\> echo '{"queryKey":"ias.VEMtSCGU","after":"2333"}' | /var/www/html/phab/arcanist/bin/arc call-conduit --conduit-uri https://phabricator.wikimedia.org/ --conduit-token "api-x" diffusion.repository.search --  > foojson3
# $:acko\> echo '{"queryKey":"ias.VEMtSCGU","after":"1639"}' | /var/www/html/phab/arcanist/bin/arc call-conduit --conduit-uri https://phabricator.wikimedia.org/ --conduit-token "api-x" diffusion.repository.search --  > foojson4 # fails, see above
$:acko\> cat foojson1 | jq -r '.response.data[] | select(.fields.shortName == null).fields.shortName' | wc -l
0
$:acko\> cat foojson2 | jq -r '.response.data[] | select(.fields.shortName == null).fields.shortName' | wc -l
2
$:acko\> cat foojson3 | jq -r '.response.data[] | select(.fields.shortName == null).fields.shortName' | wc -l
7
$:acko\> cat foojson1 | jq -r '.response.data[] | select(.fields.name | contains(" ")).fields.name' | wc -l
1
$:acko\> cat foojson2 | jq -r '.response.data[] | select(.fields.name | contains(" ")).fields.name' | wc -l
1
$:acko\> cat foojson3 | jq -r '.response.data[] | select(.fields.name | contains(" ")).fields.name' | wc -l
5
$:acko\> cat foojson1 | jq -r '.response.data[] | select(.fields.callsign == null).fields.callsign' | wc -l
98
$:acko\> cat foojson2 | jq -r '.response.data[] | select(.fields.callsign == null).fields.callsign' | wc -l
97
$:acko\> cat foojson3 | jq -r '.response.data[] | select(.fields.callsign == null).fields.callsign' | wc -l
83

Cloning everything except for five manually skipped non-public repos, and ignoring everything on the fourth and last page of repos that Diffusion won't list:

#/bin/sh
echo '{"queryKey":"ias.VEMtSCGU"}' | /arcanist/bin/arc call-conduit diffusion.repository.search -- > foojson1
echo '{"queryKey":"ias.VEMtSCGU","after":"2632"}' | /arcanist/bin/arc call-conduit diffusion.repository.search --  > foojson2
echo '{"queryKey":"ias.VEMtSCGU","after":"2333"}' | /arcanist/bin/arc call-conduit diffusion.repository.search --  > foojson3
# echo '{"queryKey":"ias.VEMtSCGU","after":"1639"}' | /arcanist/bin/arc diffusion.repository.search --  > foojson4 # fails, see above
for f in foojson1 foojson2 foojson3 #foojson4
do
  cat $f | jq -r '.response.data[] | select(.fields.shortName != null) | .fields.shortName' | while read -r line ; do
    git clone https://phabricator.wikimedia.org/source/$line
  done
  cat $f | jq -r '.response.data[] | select((.fields.shortName == null) and (.fields.callsign != null)) | .fields.callsign' | while read -r line ; do
    git clone https://phabricator.wikimedia.org/diffusion/$line/
  done
done

Getting raw commit and author data output:

DEADLINE="2019-01-25"
echo "╔═══════════════════════════════════════════════════════╗"
echo "║ Total number of commits per repo, only in git master: ║"
echo "╚═══════════════════════════════════════════════════════╝"
for i in $( ls ); do
        if [ -d $i ]; then
                cd $i
                if [ -d ".git" ]; then
                        git log --after=$DEADLINE --pretty=oneline | wc -l
                fi
        cd .. # leave module
        fi
done
echo "╔═════════════════╗"
echo "║ Commit authors: ║"
echo "╚═════════════════╝"

for i in $( ls ); do
        if [ -d $i ]; then
                cd $i
#		echo "======" $i
                if [ -d ".git" ]; then
                        # Get all authors for all the commits, sorted by number of commits:
                        git log --after=$DEADLINE --author='' --pretty=format:"%ae" | sort | uniq -c | sort -rn
                fi
        cd .. # leave module
        fi
done

Then remove all fatal: your current branch 'master' does not have any commits yet lines, then sort, merge, and sum up in spreadsheet app.

Slightly incomplete result (due to five repos ignored, and page 4 of results ignored) but acceptable ballpark figure:

2558 code commits by 78 different email addresses (4 of them @users.noreply.github.com; 12 of them @tools.eqiad.wmflabs) since 2019-01-25.