<commit_before>﻿namespace OctoHook
{
	using Octokit;
	using Octokit.Events;
	using System;
	using System.Text.RegularExpressions;
	using System.Linq;
	using System.Collections.ObjectModel;
	using OctoHook.CommonComposition;
	using System.Threading.Tasks;
	using OctoHook.Diagnostics;
	using System.Collections.Generic;
	using System.Globalization;
	using System.Reflection;
	using OctoHook.Properties;

	[Component]
	public class AutoTask : IOctoJob<IssuesEvent>
	{
		internal const string SectionBegin = "<!-- Begin OctoHook.AutoTask -->";
		internal const string SectionEnd = "<!-- End OctoHook.AutoTask -->";

		internal static readonly string header = Strings.FormatHeader(ThisAssembly.InformationalVersion,
			Strings.Wiki, Strings.Title, Strings.Note);
		static readonly string taskLinkExpr = @"-\s\[(\s|x|X)\]\s{0}.+$";

		static readonly ITracer tracer = Tracer.Get<AutoTask>();
		static readonly Regex issueLinkExpr = new Regex(@"((?<owner>\w+)/(?<repo>\w+))?#(?<number>\d+)", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
		static readonly Regex headerExpr = new Regex(@"<!-- This section was generated by OctoHook v[^\s]+ -->", RegexOptions.Compiled);

		private IGitHubClient github;

		public AutoTask(IGitHubClient github)
		{
			this.github = github;
		}

		public async Task ProcessAsync(IssuesEvent @event)
		{
			// Need to retrieve the full issue, since the event only contains the title
			var issue = await github.Issue.Get(@event.Repository.Owner.Login, @event.Repository.Name, @event.Issue.Number);

			foreach (var link in issueLinkExpr.Matches(issue.Body)
				.OfType<Match>()
				.Where(m => m.Success)
				.Select(m => new
				{
					// We support cross-repo links too, see https://github.com/blog/967-github-secrets
					Owner = string.IsNullOrEmpty(m.Groups["owner"].Value) ? @event.Repository.Owner.Login : m.Groups["owner"].Value,
					Repo = string.IsNullOrEmpty(m.Groups["repo"].Value) ? @event.Repository.Name : m.Groups["repo"].Value,<commit_msg>Prevent reentrancy by skipping task list links<commit_after>﻿namespace OctoHook
{
	using Octokit;
	using Octokit.Events;
	using System;
	using System.Text.RegularExpressions;
	using System.Linq;
	using System.Collections.ObjectModel;
	using OctoHook.CommonComposition;
	using System.Threading.Tasks;
	using OctoHook.Diagnostics;
	using System.Collections.Generic;
	using System.Globalization;
	using System.Reflection;
	using OctoHook.Properties;

	[Component]
	public class AutoTask : IOctoJob<IssuesEvent>
	{
		internal const string SectionBegin = "<!-- Begin OctoHook.AutoTask -->";
		internal const string SectionEnd = "<!-- End OctoHook.AutoTask -->";

		internal static readonly string header = Strings.FormatHeader(ThisAssembly.InformationalVersion,
			Strings.Wiki, Strings.Title, Strings.Note);
		static readonly string taskLinkExpr = @"-\s\[(\s|x|X)\]\s{0}.+$";

		static readonly ITracer tracer = Tracer.Get<AutoTask>();
		static readonly Regex issueLinkExpr = new Regex(@"(?<task>-\s\[(\s|x|X)\]\s)?((?<owner>\w+)/(?<repo>\w+))?#(?<number>\d+)", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
		static readonly Regex headerExpr = new Regex(@"<!-- This section was generated by OctoHook v[^\s]+ -->", RegexOptions.Compiled);

		private IGitHubClient github;

		public AutoTask(IGitHubClient github)
		{
			this.github = github;
		}

		public async Task ProcessAsync(IssuesEvent @event)
		{
			// Need to retrieve the full issue, since the event only contains the title
			var issue = await github.Issue.Get(@event.Repository.Owner.Login, @event.Repository.Name, @event.Issue.Number);

			foreach (var link in issueLinkExpr.Matches(issue.Body)
				.OfType<Match>()
                // Skip the links that are incoming links from a task list 
                // themselves (like the ones we generate!)
				.Where(m => m.Success && !m.Groups["task"].Success)
				.Select(m => new
				{
					// We support cross-repo links too, see https://github.com/blog/967-github-secrets
					Owner = string.IsNullOrEmpty(m.Groups["owner"].Value) ? @event.Repository.Owner.Login : m.Groups["owner"].Value,
					Repo = string.IsNullOrEmpty(m.Groups["repo"].Value) ? @event.Repository.Name : m.Groups["repo"].Value,
{'fraction_non_alphanumeric': 0.1379638439581351, 'fraction_numerical': 0.0019029495718363464, 'mean_word_length': 4.27603513174404, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 26, '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': '4599242', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1285, 'n_words': 309}