Skip to content

Commit 2f4e333

Browse files
committedJan 17, 2023
Merge branch 'master' into development
* master: Bug 1805455: Remove Bugzilla-updating logic from Phabricator uplift extension (mozilla-conduit#35)
2 parents 9817301 + ef80945 commit 2f4e333

File tree

1 file changed

+0
-124
lines changed

1 file changed

+0
-124
lines changed
 

‎moz-extensions/src/differential/customfield/DifferentialUpliftRequestCustomField.php

-124
Original file line numberDiff line numberDiff line change
@@ -72,95 +72,6 @@ public function shouldAppearInApplicationTransactions() {
7272
return true;
7373
}
7474

75-
/* Set QE required flag on the relevant Bugzilla bug. */
76-
public function setManualQERequiredFlag(int $bug) {
77-
// Construct request for setting `qe-verify` flag, see
78-
// https://bmo.readthedocs.io/en/latest/api/core/v1/bug.html#update-bug
79-
$url = id(new PhutilURI(PhabricatorEnv::getEnvConfig('bugzilla.url')))
80-
->setPath('/rest/bug/'.$bug);
81-
$api_key = PhabricatorEnv::getEnvConfig('bugzilla.automation_api_key');
82-
83-
// Encode here because `setData` below will fail due to nested arrays.
84-
$data = phutil_json_encode(
85-
array(
86-
'flags' => array(
87-
array(
88-
'name' => 'qe-verify',
89-
'status' => '?',
90-
),
91-
),
92-
),
93-
);
94-
95-
$future = id(new HTTPSFuture($url))
96-
->addHeader('Accept', 'application/json')
97-
->addHeader('Content-Type', 'application/json')
98-
->addHeader('User-Agent', 'Phabricator')
99-
->addHeader('X-Bugzilla-API-Key', $api_key)
100-
->setData($data)
101-
->setMethod('PUT')
102-
->setTimeout(PhabricatorEnv::getEnvConfig('bugzilla.timeout'));
103-
104-
try {
105-
list($status, $body) = $future->resolve();
106-
$status_code = (int) $status->getStatusCode();
107-
108-
# Return an error string and invalidate transaction if Bugzilla can't be contacted.
109-
$body = phutil_json_decode($body);
110-
if (array_key_exists("error", $body) && $body["error"]) {
111-
throw new Exception(
112-
'Could not set `qe-verify` on Bugzilla: status code: '.$status_code.'! Please file a bug.'
113-
);
114-
}
115-
116-
} catch (PhutilJSONParserException $ex) {
117-
throw new Exception(
118-
'Expected invalid JSON response from BMO while setting `qe-verify` flag.'
119-
);
120-
}
121-
}
122-
123-
/* Comment the uplift request form on the relevant Bugzilla bug. */
124-
public function commentUpliftOnBugzilla(int $bug) {
125-
// Construct request for leaving a comment, see
126-
// https://bmo.readthedocs.io/en/latest/api/core/v1/comment.html#create-comments
127-
$url = id(new PhutilURI(PhabricatorEnv::getEnvConfig('bugzilla.url')))
128-
->setPath('/rest/bug/'.$bug.'/comment');
129-
$api_key = PhabricatorEnv::getEnvConfig('bugzilla.automation_api_key');
130-
131-
$data = array(
132-
'comment' => $this->getRemarkup(),
133-
'is_markdown' => true,
134-
'is_private' => false,
135-
);
136-
137-
$future = id(new HTTPSFuture($url))
138-
->addHeader('Accept', 'application/json')
139-
->addHeader('User-Agent', 'Phabricator')
140-
->addHeader('X-Bugzilla-API-Key', $api_key)
141-
->setData($data)
142-
->setMethod('POST')
143-
->setTimeout(PhabricatorEnv::getEnvConfig('bugzilla.timeout'));
144-
145-
try {
146-
list($status, $body) = $future->resolve();
147-
$status_code = (int) $status->getStatusCode();
148-
149-
# Return an error string and invalidate transaction if Bugzilla can't be contacted.
150-
$body = phutil_json_decode($body);
151-
if (array_key_exists("error", $body) && $body["error"]) {
152-
throw new Exception(
153-
'Could not leave a comment on Bugzilla: status code '.$status_code.'! Please file a bug.',
154-
);
155-
}
156-
157-
} catch (PhutilJSONParserException $ex) {
158-
throw new Exception(
159-
'Received invalid JSON response from BMO while leaving a comment.'
160-
);
161-
}
162-
}
163-
16475
/* -( Edit View )---------------------------------------------------------- */
16576

16677
public function shouldAppearInEditView() {
@@ -341,10 +252,6 @@ public function validateUpliftForm(array $form): array {
341252
return $validation_errors;
342253
}
343254

344-
public function qeRequired() {
345-
return $this->getValue()['Needs manual QE test'] === true;
346-
}
347-
348255
public function validateApplicationTransactions(
349256
PhabricatorApplicationTransactionEditor $editor,
350257
$type, array $xactions) {
@@ -371,37 +278,6 @@ public function validateApplicationTransactions(
371278
return $errors;
372279
}
373280

374-
// Update Bugzilla when applying effects.
375-
public function applyApplicationTransactionExternalEffects(
376-
PhabricatorApplicationTransaction $xaction
377-
) {
378-
$ret = parent::applyApplicationTransactionExternalEffects($xaction);
379-
380-
// Don't update Bugzilla when the field is empty.
381-
if (empty($this->getvalue())) {
382-
return $ret;
383-
}
384-
385-
// Similar idea to `BugStore::resolveBug`.
386-
// We should have already checked for the bug during validation.
387-
$bugzillaField = new DifferentialBugzillaBugIDField();
388-
$bugzillaField->setObject($this->getObject());
389-
(new PhabricatorCustomFieldStorageQuery())
390-
->addField($bugzillaField)
391-
->execute();
392-
$bug = $bugzillaField->getValue();
393-
394-
// Always comment the uplift form.
395-
$this->commentUpliftOnBugzilla($bug);
396-
397-
// If QE is required, set the Bugzilla flag.
398-
if ($this->qeRequired()) {
399-
$this->setManualQERequiredFlag($bug);
400-
}
401-
402-
return $ret;
403-
}
404-
405281
// When storing the value convert the question => answer mapping to a JSON string.
406282
public function getValueForStorage(): string {
407283
return phutil_json_encode($this->getValue());

0 commit comments

Comments
 (0)
Failed to load comments.