Commit: 353abb3d0bbec66f5f4d76f29dd6717d7babb5a9 Author: Peter Kokot <[email protected]> Wed, 22 May 2019 01:19:34 +0200 Parents: 3c344392bdbb711da6c6cbc0611fe4fbc19f1599 Branches: master
Link: http://git.php.net/?p=web/bugs.git;a=commitdiff;h=353abb3d0bbec66f5f4d76f29dd6717d7babb5a9 Log: Fix #64249: Bug tracker doesn't send notifies on adding of pull requests This now sends also notification about GitHub pull request being attached to a bug report. Bugs: https://bugs.php.net/64249 Changed paths: M www/gh-pull-add.php Diff: diff --git a/www/gh-pull-add.php b/www/gh-pull-add.php index 3f1d91a..4dac961 100644 --- a/www/gh-pull-add.php +++ b/www/gh-pull-add.php @@ -17,107 +17,107 @@ bugs_authenticate($user, $pw, $logged_in, $user_flags); /// Input vars $bug_id = !empty($_REQUEST['bug']) ? (int) $_REQUEST['bug'] : 0; if (empty($bug_id)) { - $bug_id = !empty($_REQUEST['bug_id']) ? (int) $_REQUEST['bug_id'] : 0; + $bug_id = !empty($_REQUEST['bug_id']) ? (int) $_REQUEST['bug_id'] : 0; } if (empty($bug_id)) { - response_header('Error :: no bug selected'); - display_bug_error('No bug selected to add a patch to (no bug or bug_id!)'); - response_footer(); - exit; + response_header('Error :: no bug selected'); + display_bug_error('No bug selected to add a patch to (no bug or bug_id!)'); + response_footer(); + exit; } $bugRepository = $container->get(BugRepository::class); if (!($buginfo = $bugRepository->findOneById($bug_id))) { - response_header('Error :: invalid bug selected'); - display_bug_error("Invalid bug #{$bug_id} selected"); - response_footer(); - exit; + response_header('Error :: invalid bug selected'); + display_bug_error("Invalid bug #{$bug_id} selected"); + response_footer(); + exit; } $package_name = $buginfo['package_name']; // captcha is not necessary if the user is logged in if (!$logged_in) { - $captcha = $container->get(Captcha::class); + $captcha = $container->get(Captcha::class); } $show_bug_info = bugs_has_access($bug_id, $buginfo, $pw, $user_flags); if (!$show_bug_info) { - response_header('Private report'); - display_bug_error("The bug #{$bug_id} is not available to public"); - response_footer(); - exit; + response_header('Private report'); + display_bug_error("The bug #{$bug_id} is not available to public"); + response_footer(); + exit; } $pullinfo = $container->get(GitHub::class); $pullRequestRepository = $container->get(PullRequestRepository::class); if (isset($_POST['addpull'])) { - $errors = []; - if (empty($_POST['repository'])) { - $errors[] = 'No repository selected'; - } - if (empty($_POST['pull_id'])) { - $errors[] = 'No Pull request selected'; - } - - if (!$logged_in) { - try { - $email = isset($_POST['email']) ? $_POST['email'] : ''; - - if (!is_valid_email($email, $logged_in)) { - $errors[] = 'Email address must be valid!'; - } - - /** - * Check if session answer is set, then compare - * it with the post captcha value. If it's not - * the same, then it's an incorrect password. - */ - if (!isset($_SESSION['answer']) || $_POST['captcha'] != $_SESSION['answer']) { - $errors[] = 'Incorrect Captcha'; - } - - if (count($errors)) { - throw new Exception(''); - } - - } catch (Exception $e) { - $pulls = $pullRequestRepository->findAllByBugId($bug_id); - include "{$ROOT_DIR}/templates/addghpull.php"; - exit; - } - } else { - $email = $auth_user->email; - } - - if (!count($errors)) { - try { - $newpr = $pullinfo->attach($bug_id, $_POST['repository'], $_POST['pull_id'], $email); - } catch(\Exception $e) { - $errors = ['Could not attach pull request to Bug #'.$bug_id]; - - if ($e->errorInfo[1] === 1062) { - $errors[] = 'This pull request is already added.'; - } - - if ('dev' === $container->get('env')) { - $errors[] = $e->getMessage(); - } - } - } - - if (count($errors)) { - $pulls = $pullRequestRepository->findAllByBugId($bug_id); - include "{$ROOT_DIR}/templates/addghpull.php"; - exit; - } - - // Add a comment to the bug report. - $text = <<<TXT + $errors = []; + if (empty($_POST['repository'])) { + $errors[] = 'No repository selected'; + } + if (empty($_POST['pull_id'])) { + $errors[] = 'No Pull request selected'; + } + + if (!$logged_in) { + try { + $email = isset($_POST['email']) ? $_POST['email'] : ''; + + if (!is_valid_email($email, $logged_in)) { + $errors[] = 'Email address must be valid!'; + } + + /** + * Check if session answer is set, then compare + * it with the post captcha value. If it's not + * the same, then it's an incorrect password. + */ + if (!isset($_SESSION['answer']) || $_POST['captcha'] != $_SESSION['answer']) { + $errors[] = 'Incorrect Captcha'; + } + + if (count($errors)) { + throw new Exception(''); + } + + } catch (Exception $e) { + $pulls = $pullRequestRepository->findAllByBugId($bug_id); + include "{$ROOT_DIR}/templates/addghpull.php"; + exit; + } + } else { + $email = $auth_user->email; + } + + if (!count($errors)) { + try { + $newpr = $pullinfo->attach($bug_id, $_POST['repository'], $_POST['pull_id'], $email); + } catch(\Exception $e) { + $errors = ['Could not attach pull request to Bug #'.$bug_id]; + + if ($e->errorInfo[1] === 1062) { + $errors[] = 'This pull request is already added.'; + } + + if ('dev' === $container->get('env')) { + $errors[] = $e->getMessage(); + } + } + } + + if (count($errors)) { + $pulls = $pullRequestRepository->findAllByBugId($bug_id); + include "{$ROOT_DIR}/templates/addghpull.php"; + exit; + } + + // Add a comment to the bug report. + $text = <<<TXT The following pull request has been associated: Patch Name: {$newpr->title} @@ -125,16 +125,15 @@ On GitHub: {$newpr->html_url} Patch: {$newpr->patch_url} TXT; - $res = bugs_add_comment($bug_id, $auth_user->email, $auth_user->name, $text, 'patch'); + $res = bugs_add_comment($bug_id, $email, $auth_user->name, $text, 'patch'); - // Send emails - // TODO: enable also mailing - //mail_bug_updates($buginfo, $buginfo, $auth_user->email, $text, 4, $bug_id); + // Send emails + mail_bug_updates($buginfo, $buginfo, $email, $text, 4, $bug_id); - $pulls = $pullRequestRepository->findAllByBugId($bug_id); - $errors = []; - include "{$ROOT_DIR}/templates/addghpull.php"; - exit; + $pulls = $pullRequestRepository->findAllByBugId($bug_id); + $errors = []; + include "{$ROOT_DIR}/templates/addghpull.php"; + exit; } $email = isset($_GET['email']) ? $_GET['email'] : ''; -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
