<commit_before><?php

# Copyright (c) 2012 <NAME>
# Licensed under the MIT license

if ( false === include_once( config_get( 'plugin_path' ) . 'Source/MantisSourceGitBasePlugin.class.php' ) ) {
	return;
}

require_once( config_get( 'core_path' ) . 'json_api.php' );

class SourceGithubPlugin extends MantisSourceGitBasePlugin {

	const PLUGIN_VERSION = '2.1.0-dev';
	const FRAMEWORK_VERSION_REQUIRED = '2.0.0';

	public $linkPullRequest = '/pull/%s';

	public function register() {
		$this->name = plugin_lang_get( 'title' );
		$this->description = plugin_lang_get( 'description' );

		$this->version = self::PLUGIN_VERSION;
		$this->requires = array(
			'MantisCore' => self::MANTIS_VERSION,
			'Source' => self::FRAMEWORK_VERSION_REQUIRED,
		);

		$this->author = '<NAME>';
		$this->contact = '<EMAIL>';
		$this->url = 'https://github.com/mantisbt-plugins/source-integration/';
	}

	public $type = 'github';

	public function hooks() {
		return parent::hooks() + array(
			'EVENT_REST_API_ROUTES' => 'routes',
		);
	}

	/**
	 * Add the RESTful routes handled by this plugin.
	 *
	 * @param string $p_event_name The event name
	 * @param array  $p_event_args The event arguments
	 * @return void
	 */
	public function routes( $p_event_name, $p_event_args ) {
		$t_app = $p_event_args['app'];
		$t_plugin = $this;
		$t_app->group(
			plugin_route_group(),
			function() use ( $t_app, $t_plugin ) {
				$t_app->post( '/{id}/webhook', [$t_plugin, 'route_webhook'] );
			}
		);
	}

	/**
	 * RESTful route to create GitHub checkin webhook
	 *
	 * @param Slim\Http\Request  $p_request
	 * @param Slim\Http\Response $p_response
	 * @param array              $p_args
	 *<commit_msg>Load javascript resource<commit_after><?php

# Copyright (c) 2012 <NAME>
# Licensed under the MIT license

if ( false === include_once( config_get( 'plugin_path' ) . 'Source/MantisSourceGitBasePlugin.class.php' ) ) {
	return;
}

require_once( config_get( 'core_path' ) . 'json_api.php' );

class SourceGithubPlugin extends MantisSourceGitBasePlugin {

	const PLUGIN_VERSION = '2.1.0-dev';
	const FRAMEWORK_VERSION_REQUIRED = '2.0.0';

	public $linkPullRequest = '/pull/%s';

	public function register() {
		$this->name = plugin_lang_get( 'title' );
		$this->description = plugin_lang_get( 'description' );

		$this->version = self::PLUGIN_VERSION;
		$this->requires = array(
			'MantisCore' => self::MANTIS_VERSION,
			'Source' => self::FRAMEWORK_VERSION_REQUIRED,
		);

		$this->author = '<NAME>';
		$this->contact = '<EMAIL>';
		$this->url = 'https://github.com/mantisbt-plugins/source-integration/';
	}

	public $type = 'github';

	public function resources( $p_event ) {
		# Only include the javascript when it's actually needed
		parse_str( parse_url( $_SERVER['REQUEST_URI'], PHP_URL_QUERY ), $t_query );
		if( array_key_exists( 'page', $t_query ) ) {
			$t_page = basename( $t_query['page'] );
			if( $t_page == 'repo_update_page' ) {
				return '<script src="' . plugin_file( 'sourcegithub.js' ) . '"></script>';
			}
		}
		return null;
	}

	public function hooks() {
		return parent::hooks() + array(
			"EVENT_LAYOUT_RESOURCES" => "resources",
			'EVENT_REST_API_ROUTES' => 'routes',
		);
	}

	/**
	 * Add the RESTful routes handled by this plugin.
	 *
	 * @param string $p_event_name The event name
	 * @param array  $p_event_args The event arguments
	 * @return void
	 */
	public function routes( $p_event_name, $p_event_args ) {
		$t_app = $p_event_args['app'];
		$t_plugin = $this;
		$t_app->group(
			plugin_route_group(),
			function() use ( $t_app, $t_plugin ) {
				$t_app->post( '/{id}/webhook', [$t_plugin, 'route_webhook'] );
			}
		);
	}

	/**
	 * RESTful route to create GitHub checkin webhook
	 *
	 * @param Slim\Http\Request  $p_request
	 * @param Slim\Http\Response $p_response
	 * @param array              $p_args
	 *
{'fraction_non_alphanumeric': 0.15785340314136126, 'fraction_numerical': 0.005235602094240838, 'mean_word_length': 3.930322580645161, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 36, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3075772', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1350, 'n_words': 289}