phabricator get commit author from feed story for

2019-06-14 16:56发布

问题:

I am trying to integrate phabricator with jabber chat. I have created a bot that sends messages to the commit author in jabber chat for every new feed query. My requirement is that how do I get the original author of a commit if the feed story is a concern,audit or commnet. I want to notify the author of the commit of any concerns raised with his commit. Do I need to analyse the story to get this informaiton? How do I go about doing this?

Thanks in advance

回答1:

The story object should have a data element that will include information about the Author and committer. Like so:

"PHID-STRY-spjfpdv4wuigblmh3ygb" : {
    "class"            : "PhabricatorFeedStoryCommit",
    "epoch"            : 1409840112,
    "authorPHID"       : "PHID-USER-tcyihgi43sw6o7yrnhu5",
    "chronologicalKey" : "6055220066741547443",
    "data"             : {
      "commitPHID"    : "PHID-CMIT-ievqiimtsnlfhlk5imqq",
      "summary"       : "[blah]",
      "authorName"    : "Author Name <author_email@example.com>",
      "authorPHID"    : "PHID-USER-tcyihgi43sw6o7yrnhu5",
      "committerName" : "Commiter Name <commiter_email@example.com>",
      "committerPHID" : "PHID-USER-tcyihgi43sw6o7yrnhu5"
    }
}

If not, it should have an objectPHID:

"PHID-STRY-mqlkjzwkbr3th4h5n2eg" : {
    "class"            : "PhabricatorApplicationTransactionFeedStory",
    "epoch"            : 1409841382,
    "authorPHID"       : "PHID-USER-2bubef6xonwicvaool4w",
    "chronologicalKey" : "6055222630292077307",
    "data"             : {
        "objectPHID"       : "PHID-CMIT-is7pmo5nyvv4eruq2msn",
        "transactionPHIDs" : [
            "PHID-XACT-CMIT-svvkzf7dfplzdxp"
        ]
    }
}

You can query from there using conduit calls.



回答2:

The best way to understand and test this is the following http://phabricator.yourhost.com/conduit/method/feed.query/
click [call method]
This will return a list of changes that you will be interested in: "objectPHID": "PHID-DREV-xxxxxxx",
...
Now http://phabricator.yourhost.com/conduit/method/differential.query/
set phids => ["PHID-DREV-xxxxxxx"]
...
This will return "authorPHID": "PHID-USER-xxxxx", and "reviewers": ["xxxx","xxxx","xxxx"]
...
I also suggest reviewing /src/infrastructure/daemon/bot/handler/PhabricatorBotFeedNotificationHandler.php

Now the code

$stories = $this->getConduit()->callMethodSynchronous(
    'feed.query',
    array(
       'limit' => $config_page_size,
       'after' => $chrono_key_cursor,
       'view' => 'text',
    )
);

foreach ($stories as $story) {
    $objects = $this->getConduit()->callMethodSynchronous(
        'phid.lookup',
        array(
            'names' => array($story['objectPHID']),
        )
    );

    $diff_query_results = $this->getConduit()->callMethodSynchronous(
        'differential.query',
        array(
            'phids' => array($story['objectPHID']),
    ));

    foreach ($diff_query_results as $diff_query) {
        $authorResults = $this->getConduit()->callMethodSynchronous(
        'phid.lookup',
        array(
            'names' => array($diff_query['authorPHID']),
        )
    );

    $message .= ' '.$objects[$story['objectPHID']]['uri'];
    foreach ($authorResults as $author) {
       $authorName = $author['name'];
       print_r ($authorName);
    }

    $reviewersResults = $this->getConduit()->callMethodSynchronous(
        'phid.lookup',
        array(
            'names' => $diff_query['reviewers'],
        )
    );


    foreach ($reviewersResults as $reviewer) {
        $reviewerName = $reviewer['name'];
        print_r ($reviewerName );
    }
}


回答3:

I queried the feed.query. and extracted the authorPHID and objectPHID if available. With the objectPHID I queried differnetial.query conduit method to find out the reviewers and ccs. The ccs is an array of users that have to receive a cc of the message. Then i used the user.query conduit method to extract usernames and mapped them to jabber usernames and sent the messages.