<commit_before><?php

	loadlib("users_acl");
	loadlib("wof_pipeline");
	loadlib("wof_repo");

	########################################################################

	function api_wof_pipeline_create() {

		if (! users_acl_check_access($GLOBALS['cfg']['user'], 'can_upload_pipelines')) {
			api_output_error(403, "You don't have permission to update pipelines.");
		}

		$meta_json = post_str('meta_json');

		if (! $meta_json) {
			api_output_error(400, "Please include 'meta_json' arguments.");
		}

		$meta = json_decode($meta_json, 'as hash');
		$repo = $meta['repo'];

		if (! $repo) {
			api_output_error(400, "Please include a 'repo' value in your 'meta_json'.");
		}

		$rsp = wof_pipeline_create($meta);
		api_output_ok($rsp);
	}

	########################################################################

	function api_wof_pipeline_update() {

		if (! users_acl_check_access($GLOBALS['cfg']['user'], 'can_upload_pipelines')) {
			api_output_error(403, "You don't have permission to update pipelines.");
		}

		$id = post_int64('id');
		$action = post_str('action');

		if (! $id || ! $action) {
			api_output_error(400, "Please include 'id' and 'action' arguments.");
		}

		$rsp = wof_pipeline_get($id);
		if (! $rsp) {
			api_output_error(404, "Could not find pipeline $id");
		}
		$pipeline = $rsp['pipeline'];

		if ($action == 'cancel') {
			wof_pipeline_phase($pipeline, 'cancelled');
			wof_pipeline_cleanup($pipeline);
			wof_repo_set_status($pipeline['repo'], 'ready');
		} else if ($pipeline['phase'] == 'error' && $action == 'retry') {
			if (! $pipeline['meta']['last_phase']) {
				api_output_error(400, "Could not determine the pipeline's last_phase.");
			}
			wof_pipeline_phase($pipeline, 'retry');
		} else if ($pipeline['phase'] == 'confirm' && $action == 'confirm') {
			wof_pipeline_phase($pipeline, 'confirmed');
		}

		// Reload the pipeline
		$rsp = wof_pipeline_get($id);
		api_output_ok($rsp);
	}

	# the end<commit_msg>:wrench: only reset repo status if the pipeline is currently operating on it<commit_after><?php

	loadlib("users_acl");
	loadlib("wof_pipeline");
	loadlib("wof_repo");

	########################################################################

	function api_wof_pipeline_create() {

		if (! users_acl_check_access($GLOBALS['cfg']['user'], 'can_upload_pipelines')) {
			api_output_error(403, "You don't have permission to update pipelines.");
		}

		$meta_json = post_str('meta_json');

		if (! $meta_json) {
			api_output_error(400, "Please include 'meta_json' arguments.");
		}

		$meta = json_decode($meta_json, 'as hash');
		$repo = $meta['repo'];

		if (! $repo) {
			api_output_error(400, "Please include a 'repo' value in your 'meta_json'.");
		}

		$rsp = wof_pipeline_create($meta);
		api_output_ok($rsp);
	}

	########################################################################

	function api_wof_pipeline_update() {

		if (! users_acl_check_access($GLOBALS['cfg']['user'], 'can_upload_pipelines')) {
			api_output_error(403, "You don't have permission to update pipelines.");
		}

		$id = post_int64('id');
		$action = post_str('action');

		if (! $id || ! $action) {
			api_output_error(400, "Please include 'id' and 'action' arguments.");
		}

		$rsp = wof_pipeline_get($id);
		if (! $rsp) {
			api_output_error(404, "Could not find pipeline $id");
		}
		$pipeline = $rsp['pipeline'];

		if ($action == 'cancel') {
			wof_pipeline_phase($pipeline, 'cancelled');
			wof_pipeline_cleanup($pipeline);
			$rsp = wof_repo_get_status($pipeline['repo']);
			if ($rsp['status'] &&
			    strpos($rsp['status'], "pipeline $id") !== false) {
				wof_repo_set_status($pipeline['repo'], 'ready');
			}
		} else if ($pipeline['phase'] == 'error' && $action == 'retry') {
			if (! $pipeline['meta']['last_phase']) {
				api_output_error(400, "Could not determine the pipeline's last_phase.");
			}
			wof_pipeline_phase($pipeline, 'retry');
		} else if ($pipeline['phase'] == 'confirm' && $action == 'confirm') {
			wof_pipeline_phase($pipeline, 'confirmed');
		}

		// Reload the pipeline
		$rsp = wof_pipeline_get($id);
		api_output_ok($rsp);
	}

	# the end
{'fraction_non_alphanumeric': 0.23901965542344092, 'fraction_numerical': 0.011162339238049017, 'mean_word_length': 5.161434977578475, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '3502465', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1397, 'n_words': 271}