phabricator如何从feed.http-hooks生成diff url

时间:2018-02-20 04:21:18

标签: phabricator

Phabricator版本d2cff6a2cf01396f6337edfadd1f7df7cce1277d(2017年11月17日)

我想得到差异的网址,比如

val df = Seq(
  (0, 0, 0, 0.0, 0),
  (1, 0, 0, 0.1, 1),
  (0, 1, 0, 0.11, 1),
  (0, 0, 1, 0.12, 1),
  (1, 1, 0, 0.24, 2),
  (1, 0, 1, 0.27, 2),
  (0, 1, 1, 0.3, 2),
  (1, 1, 1, 0.4, 3)
).toDF("A", "B", "C", "rate", "total")

val oneChannelDF = df.filter($"total" === 1)
val twoChannelDF = df.filter($"total" === 2)

val channels = df.columns.filter(v => !(v.contains("rate") || v.contains("total")))
// channels: Array[String] = Array(A, B, C)

val ratesMap = channels.foldLeft( Map[String, Double]() ){ (acc, c) =>
  acc + (c -> oneChannelDF.select("rate").where(col(c) === 1).head.getDouble(0))
}
// ratesMap: scala.collection.immutable.Map[String,Double] = Map(A -> 0.1, B -> 0.11, C -> 0.12)

val probsDF = channels.foldLeft( twoChannelDF ){ (acc, c) =>
  acc.withColumn( "prob_" + c, col(c) * ratesMap.getOrElse(c, 0.0) )
}

probsDF.show
// +---+---+---+----+-----+------+------+------+
// |  A|  B|  C|rate|total|prob_A|prob_B|prob_C|
// +---+---+---+----+-----+------+------+------+
// |  1|  1|  0|0.24|    2|   0.1|  0.11|   0.0|
// |  1|  0|  1|0.27|    2|   0.1|   0.0|  0.12|
// |  0|  1|  1| 0.3|    2|   0.0|  0.11|  0.12|
// +---+---+---+----+-----+------+------+------+

来自feed.http-hooks的请求。

但是feed.http-hooks不像D4那样发送差异数字,而是发送storyID和something。

如何根据feed.http-hooks的信息创建差异URL? 我在下面做了。

客户端

http://myphabricator/D4

feed.http-hooks.sent

***headers***
Host:localhost:8085
Content-Length:441
Accept:*/*
Content-Type:application/x-www-form-urlencoded

*** bodys ***
b'storyID=94&storyType=PhabricatorApplicationTransactionFeedStory&storyData%5BobjectPHID%5D=PHID-DREV-ms2ge2gojlaqaqt54szv&storyData%5BtransactionPHIDs%5D%5BPHID-XACT-DREV-vng3mngfk7i44er%5D=PHID-XACT-DREV-vng3mngfk7i44er&storyData%5BtransactionPHIDs%5D%5BPHID-XACT-DREV-2jn767qfhgbr2uh%5D=PHID-XACT-DREV-2jn767qfhgbr2uh&storyAuthorPHID=PHID-USER-jm5w6p3zrpns57e35f5d&storyText=my.name+updated+the+diff+for+D14%3A+test.&epoch=1519094890'

*** params ***
storyText:my.name updated the diff for D14: test.
storyData[transactionPHIDs][PHID-XACT-DREV-vng3mngfk7i44er]:PHID-XACT-DREV-vng3mngfk7i44er
storyData[transactionPHIDs][PHID-XACT-DREV-2jn767qfhgbr2uh]:PHID-XACT-DREV-2jn767qfhgbr2uh
storyAuthorPHID:PHID-USER-jm5w6p3zrpns57e35f5d
storyID:94
storyType:PhabricatorApplicationTransactionFeedStory
storyData[objectPHID]:PHID-DREV-ms2ge2gojlaqaqt54szv
epoch:1519094890

1 个答案:

答案 0 :(得分:0)

您可以解析出objectPHID(在本例中为PHID-DREV-ms2ge2gojlaqaqt54szv),并使用phid.query Conduit调用来查找它引用的对象:

echo '{
  "phids": [
    "PHID-DREV-ms2ge2gojlaqaqt54szv"
  ]
}' | arc call-conduit --conduit-uri http://localhost:8085/ --conduit-token $SECRET phid.query

或者使用curl而不是arc call-conduit:

curl http://localhost:8085/api/phid.query \
-d api.token=$SECRET \
-d phids[0]=PHID-DREV-ms2ge2gojlaqaqt54szv