function bugnote_add_edit($event, $bug_id, $bugnote_id) { $bug = bug_get($bug_id); $url = string_get_bugnote_view_url_with_fqdn($bug_id, $bugnote_id); $project = project_get_name($bug->project_id); $summary = HipChatPlugin::clean_summary(bug_format_summary($bug_id, SUMMARY_FIELD)); $reporter = '@' . user_get_name(auth_get_current_user_id()); $note = bugnote_get_text($bugnote_id); $msg = sprintf(plugin_lang_get($event === 'EVENT_BUGNOTE_ADD' ? 'bugnote_created' : 'bugnote_updated'), $project, $reporter, $summary, $url, $note); $this->notify($msg, $this->get_room($project)); }
/** * Process $p_string, looking for bugnote ID references and creating bug view * links for them. * * Returns the processed string. * * If $p_include_anchor is true, include the href tag, otherwise just insert * the URL * * The bugnote tag ('~' by default) must be at the beginning of the string or * preceeded by a character that is not a letter, a number or an underscore * * if $p_include_anchor = false, $p_fqdn is ignored and assumed to true. * @param string $p_string String to be processed. * @param boolean $p_include_anchor Whether to include the href tag or just the URL. * @param boolean $p_detail_info Whether to include more detailed information (e.g. title attribute / project) in the returned string. * @param boolean $p_fqdn Whether to return an absolute or relative link. * @return string */ function string_process_bugnote_link($p_string, $p_include_anchor = true, $p_detail_info = true, $p_fqdn = false) { static $s_bugnote_link_callback = array(); $t_tag = config_get('bugnote_link_tag'); # bail if the link tag is blank if ('' == $t_tag || $p_string == '') { return $p_string; } if (!isset($s_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn])) { if ($p_include_anchor) { $s_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] = function ($p_array) use($p_detail_info, $p_fqdn) { global $g_project_override; if (bugnote_exists((int) $p_array[2])) { $t_bug_id = bugnote_get_field((int) $p_array[2], 'bug_id'); if (bug_exists($t_bug_id)) { $g_project_override = bug_get_field($t_bug_id, 'project_id'); if (access_compare_level(user_get_access_level(auth_get_current_user_id(), bug_get_field($t_bug_id, 'project_id')), config_get('private_bugnote_threshold')) || bugnote_get_field((int) $p_array[2], 'reporter_id') == auth_get_current_user_id() || bugnote_get_field((int) $p_array[2], 'view_state') == VS_PUBLIC) { $g_project_override = null; return $p_array[1] . string_get_bugnote_view_link($t_bug_id, (int) $p_array[2], (bool) $p_detail_info, (bool) $p_fqdn); } $g_project_override = null; } } return $p_array[0]; }; # end of bugnote link callback closure } else { $s_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn] = function ($p_array) { $t_bug_id = bugnote_get_field((int) $p_array[2], 'bug_id'); if ($t_bug_id && bug_exists($t_bug_id)) { return $p_array[1] . string_get_bugnote_view_url_with_fqdn($t_bug_id, (int) $p_array[2]); } else { return $p_array[0]; } }; # end of bugnote link callback closure } } $p_string = preg_replace_callback('/(^|[^\\w])' . preg_quote($t_tag, '/') . '(\\d+)\\b/', $s_bugnote_link_callback[$p_include_anchor][$p_detail_info][$p_fqdn], $p_string); return $p_string; }
/** * Gen change bugnote message. */ function gen_change_bugnote_msg($user_id, $bug_id, $bugnote_id) { $send_msg = plugin_lang_get('msg_call') . ' ' . get_username($user_id) . '! ' . plugin_lang_get('msg_action_bugnote_edit') . "\n" . plugin_lang_get('msg_bug_id') . ' ' . bug_format_id($bug_id, 'category_id') . "\n" . plugin_lang_get('msg_proj_id') . ' ' . project_get_name(bug_get_field($bug_id, 'project_id')) . "\n" . plugin_lang_get('msg_state') . ' ' . get_enum_element('status', bug_get_field($bug_id, 'status')) . "\n" . plugin_lang_get('msg_header') . ' ' . bug_get_field($bug_id, 'summary') . "\n" . plugin_lang_get('separator') . "\n" . plugin_lang_get('msg_note_change') . str_replace("\n", '', bugnote_get_text($bugnote_id)) . "\n" . plugin_lang_get('msg_initiator') . ' ' . get_auth_username() . "\n" . plugin_lang_get('separator') . "\n" . plugin_lang_get('msg_link_change_note') . ' ' . string_get_bugnote_view_url_with_fqdn($bug_id, $bugnote_id); return $send_msg; }
function string_process_bugnote_link($p_string, $p_include_anchor = true, $p_detail_info = true, $p_fqdn = false) { $t_tag = config_get('bugnote_link_tag'); # bail if the link tag is blank if ('' == $t_tag) { return $p_string; } preg_match_all('/(^|.+?)(?:(?<=^|\\W)' . preg_quote($t_tag) . '(\\d+)|$)/s', $p_string, $t_matches, PREG_SET_ORDER); $t_result = ''; if ($p_include_anchor) { foreach ($t_matches as $t_match) { $t_result .= $t_match[1]; if (isset($t_match[2])) { $t_bugnote_id = $t_match[2]; if (bugnote_exists($t_bugnote_id)) { $t_bug_id = bugnote_get_field($t_bugnote_id, 'bug_id'); if (bug_exists($t_bug_id)) { $t_result .= string_get_bugnote_view_link($t_bug_id, $t_bugnote_id, null, $p_detail_info, $p_fqdn); } else { $t_result .= $t_bugnote_id; } } } } } else { foreach ($t_matches as $t_match) { $t_result .= $t_match[1]; if (isset($t_match[2])) { $t_bugnote_id = $t_match[2]; $t_bug_id = bugnote_get_field($t_bugnote_id, 'bug_id'); # We might as well create the link here even if the bug # doesn't exist. In the case above we don't want to do # the summary lookup on a non-existant bug. But here, we # can create the link and by the time it is clicked on, the # bug may exist. $t_result .= string_get_bugnote_view_url_with_fqdn($t_bug_id, $t_bugnote_id, null); } } } return $t_result; }
function bugnote_add_edit($event, $bug_id, $bugnote_id) { $this->skip = $this->skip || gpc_get_bool('slack_skip'); $bug = bug_get($bug_id); $url = string_get_bugnote_view_url_with_fqdn($bug_id, $bugnote_id); $project = project_get_name($bug->project_id); $summary = $this->clean_summary($bug); $reporter = '@' . user_get_name(auth_get_current_user_id()); $note = bugnote_get_text($bugnote_id); $msg = sprintf(plugin_lang_get($event === 'EVENT_BUGNOTE_ADD' ? 'bugnote_created' : 'bugnote_updated'), $project, $reporter, $url, $summary, $note); $this->notify($msg, $this->get_webhook($project), $this->get_channel($project)); }
function send_bugnote_notification($bug_id, $bugnote_id, $message_key) { $bug = bug_get($bug_id); $url = string_get_bugnote_view_url_with_fqdn($bug_id, $bugnote_id); $project = project_get_name($bug->project_id); $summary = HipChatPlugin::clean_summary(bug_format_summary($bug_id, SUMMARY_FIELD)); $user_name = user_get_name(auth_get_current_user_id()); $note = bugnote_get_text($bugnote_id); $msg = sprintf(plugin_lang_get($message_key), $project, $user_name, $summary, $url, $note); $this->notify($msg, $this->get_room($project)); }