+/**
+ * FIXME: Why am I doing this? Can't we get a proper build-system for little
+ * CLI tools -- and then use prepackaged libraries?
+ */
+class PullRequest {
+
+ /**
+ * Given a link to a pull-request, determine which local repo
+ * it applies to and fetch any metadata.
+ *
+ * @param string $url
+ * @param array $repos list of locally known repos
+ * @return PullRequest|NULL
+ */
+ public static function get($url, $repos) {
+ foreach ($repos as $repo => $relPath) {
+ if (preg_match("/^https:\/\/github.com\/(.*)\/(civicrm-{$repo})\/pull\/([0-9]+)(|\/commits|\/files)$/", $url, $matches)) {
+ list ($full, $githubUser, $githubRepo, $githubPr) = $matches;
+
+ $pr = new PullRequest();
+ $pr->repo = $repo;
+ $pr->data = HttpClient::getJson("https://api.github.com/repos/$githubUser/$githubRepo/pulls/$githubPr");
+ if (empty($pr->data)) {
+ return NULL;
+ }
+
+ return $pr;
+ }
+ }
+ return NULL;
+ }
+
+ /**
+ * @var string local repo name e.g. "core", "drupal"
+ */
+ public $repo;
+
+ protected $data;
+
+ /**
+ * @return mixed
+ */
+ public function getNumber() {
+ return $this->data->number;
+ }
+
+ /**
+ * @return string name of the branch on the requestor's repo
+ */
+ public function getRequestorBranch() {
+ return $this->data->head->ref;
+ }
+
+ /**
+ * @return string URL of the requestor's repo
+ */
+ public function getRequestorRepoUrl() {
+ return $this->data->head->repo->git_url;
+ }
+}
+
+/**
+ * Class Givi
+ */