<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package commit

import (
	"regexp"

	"github.com/pkg/errors"

	"github.com/talos-systems/conform/internal/policy"
)

// JiraCheck enforces that a Jira issue is mentioned in the header.
type JiraCheck struct {
	errors []error
}

// Name returns the name of the check.
func (j *JiraCheck) Name() string {
	return "Jira issues"
}

// Message returns to check message.
func (j *JiraCheck) Message() string {
	if len(j.errors) != 0 {
		return j.errors[0].Error()
	}

	return "Jira issues are invalid"
}

// Errors returns any violations of the check.
func (j *JiraCheck) Errors() []error {
	return j.errors
}

// ValidateJiraCheck validates if a Jira issue is mentioned in the header.
func (c Commit) ValidateJiraCheck() policy.Check {
	check := &JiraCheck{}

	reg := regexp.MustCompile(`.* \[?(\w+)-[1-9]{1}\d*\]?.*`)

	if reg.MatchString(c.msg) {
		submatch := reg.FindStringSubmatch(c.msg)
		jiraProject := submatch[1]

		if !find(c.Header.Jira.Keys, jiraProject) {
			check.errors = append(check.errors, errors.Errorf("Jira project %s is not a valid jira project", jiraProject))<commit_msg>fix: change check_jira regexp<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package commit

import (
	"regexp"

	"github.com/pkg/errors"

	"github.com/talos-systems/conform/internal/policy"
)

// JiraCheck enforces that a Jira issue is mentioned in the header.
type JiraCheck struct {
	errors []error
}

// Name returns the name of the check.
func (j *JiraCheck) Name() string {
	return "Jira issues"
}

// Message returns to check message.
func (j *JiraCheck) Message() string {
	if len(j.errors) != 0 {
		return j.errors[0].Error()
	}

	return "Jira issues are invalid"
}

// Errors returns any violations of the check.
func (j *JiraCheck) Errors() []error {
	return j.errors
}

// ValidateJiraCheck validates if a Jira issue is mentioned in the header.
func (c Commit) ValidateJiraCheck() policy.Check {
	check := &JiraCheck{}

	reg := regexp.MustCompile(`.* \[?([A-Z]*)-[1-9]{1}\d*\]?.*`)

	if reg.MatchString(c.msg) {
		submatch := reg.FindStringSubmatch(c.msg)
		jiraProject := submatch[1]

		if !find(c.Header.Jira.Keys, jiraProject) {
			check.errors = append(check.errors, errors.Errorf("Jira project %s is not a valid jira project", jiraProject))
{'fraction_non_alphanumeric': 0.13452065176203107, 'fraction_numerical': 0.007578628268283441, 'mean_word_length': 3.765342960288809, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1867616', 'n_tokens_mistral': 936, 'n_tokens_neox': 896, 'n_words': 298}