<commit_before>import logging
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from django import forms
from jira import JIRAClient

log = logging.getLogger(__name__)

class JIRAOptionsForm(forms.Form):
    instance_url = forms.CharField(
        label=_("JIRA Instance URL"),
        widget=forms.TextInput(attrs={'class': 'span6', 'placeholder': 'e.g. "https://jira.atlassian.com"'}),
        help_text=_("It must be visible to the Sentry server"),
        required=True
    )
    username = forms.CharField(
        label=_("Username"),
        widget=forms.TextInput(attrs={'class': 'span6'}),
        help_text=_("Ensure the JIRA user has admin perm. on the project"),
        required=True
    )
    password = forms.CharField(
        label=_("Password"),
        widget=forms.PasswordInput(attrs={'class': 'span6'}),
        help_text=_("Only enter a value if you wish to change it"),
        required=False
    )
    default_project = forms.ChoiceField(
        label=_("Linked Project"),
    )
    ignored_fields = forms.CharField(
        label=_("Ignored Fields"),
        widget=forms.Textarea(attrs={'class': 'span11', 'placeholder': 'e.g. "components, security, customfield_10006"'}),
        help_text=_("Comma-separated list of properties that you don't want to show in the form"),
        required=False
    )

    def __init__(self, *args, **kwargs):
        super(JIRAOptionsForm, self).__init__(*args, **kwargs)

        initial = kwargs.get("initial")
        project_safe = False
        if initial:
            # make a connection to JIRA to fetch a default project.
            jira = JIRAClient(initial.get("instance_url"), initial.get("username"), initial.get("password"))
            projects_response = jira.get_projects_list()
            if projects_response.status_code == 200:
                projects = projects_response.json
                if projects:
                    project_choices = [(p.get('key'), "%s (%s)" % (p.get('name'), p.get('key'))) for p in projects]
                    project_safe = True
                    self.fields["default_project"].choices = project_choices

        if not project_safe:
            del self.fields["default_project"]
            del self.fields["ignored_fields"]

    def clean_password(self):
        """
        Don't complain if the field is empty and a password is already stored,
        no one wants to type a pw in each time they want to change it.
        """
        pw = self.cleaned_data.get("password")
        if pw:
            return pw
        else:
            old_pw = self.initial.get("password")
            if not old_pw:
                raise ValidationError("A Password is Required")
            return old_pw

    def clean(self):
        """
        try and build a JIRAClient and make a random call to make sure the
        configuration is right.
        """
        cd = self.cleaned_data

        missing_fields = False
        if not cd.get("instance_url"):
            self.errors["instance_url"] = ["Instance URL is required"]
            missing_fields = True
        if not cd.get("username"):
            self.errors["username"] = ["Username is required"]
            missing_fields = True
        if missing_fields:
            raise ValidationError("Missing Fields")

        jira = JIRAClient(cd["instance_url"], cd["username"], cd["password"])
        sut_response = jira.get_priorities()
        if sut_response.status_code == 403 or sut_response.status_code == 401:
            self.errors["username"] = ["Username might be incorrect"]
            self.errors["password"] = ["<PASSWORD>"]
            raise ValidationError("Unable to connect to JIRA: %s, if you have "
                                  "tried and failed multiple times you may have"
                                  " to enter a CAPTCHA in JIRA to re-enable API"
                                  " logins." % sut_response.status_code)
        elif sut_response.status_code == 500 or sut_response.json is None:
            raise ValidationError("Unable to connect to JIRA: Bad Response")
        elif sut_response.status_code > 200:
            raise ValidationError("Unable to connect to JIRA: %s" % sut_response.status_code)

        return cd


class JIRAIssueForm(forms.Form):

    project_key = forms.CharField(widget=forms.HiddenInput())
    project = forms.CharField(widget=forms.HiddenInput())
    issuetype = forms.ChoiceField(
        label="Issue Type",
        help_text="Changing the issue type will refresh the page with the required form fields."
    )

    summary = forms.CharField(
        label=_("Issue Summary"),
        widget=forms.TextInput(attrs={'class': 'span6'})
    )
    description = forms.CharField(
        widget=forms.Textarea(attrs={"class": 'span6'})
    )
    fixVersions = forms.MultipleChoiceField(
        label=_("Fix Version/s")
    )

    def __init__(self, *args, **kwargs):<commit_msg>ensuring fixVersions is not marked as a required field on the form<commit_after>import logging
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from django import forms
from jira import JIRAClient

log = logging.getLogger(__name__)

class JIRAOptionsForm(forms.Form):
    instance_url = forms.CharField(
        label=_("JIRA Instance URL"),
        widget=forms.TextInput(attrs={'class': 'span6', 'placeholder': 'e.g. "https://jira.atlassian.com"'}),
        help_text=_("It must be visible to the Sentry server"),
        required=True
    )
    username = forms.CharField(
        label=_("Username"),
        widget=forms.TextInput(attrs={'class': 'span6'}),
        help_text=_("Ensure the JIRA user has admin perm. on the project"),
        required=True
    )
    password = forms.CharField(
        label=_("Password"),
        widget=forms.PasswordInput(attrs={'class': 'span6'}),
        help_text=_("Only enter a value if you wish to change it"),
        required=False
    )
    default_project = forms.ChoiceField(
        label=_("Linked Project"),
    )
    ignored_fields = forms.CharField(
        label=_("Ignored Fields"),
        widget=forms.Textarea(attrs={'class': 'span11', 'placeholder': 'e.g. "components, security, customfield_10006"'}),
        help_text=_("Comma-separated list of properties that you don't want to show in the form"),
        required=False
    )

    def __init__(self, *args, **kwargs):
        super(JIRAOptionsForm, self).__init__(*args, **kwargs)

        initial = kwargs.get("initial")
        project_safe = False
        if initial:
            # make a connection to JIRA to fetch a default project.
            jira = JIRAClient(initial.get("instance_url"), initial.get("username"), initial.get("password"))
            projects_response = jira.get_projects_list()
            if projects_response.status_code == 200:
                projects = projects_response.json
                if projects:
                    project_choices = [(p.get('key'), "%s (%s)" % (p.get('name'), p.get('key'))) for p in projects]
                    project_safe = True
                    self.fields["default_project"].choices = project_choices

        if not project_safe:
            del self.fields["default_project"]
            del self.fields["ignored_fields"]

    def clean_password(self):
        """
        Don't complain if the field is empty and a password is already stored,
        no one wants to type a pw in each time they want to change it.
        """
        pw = self.cleaned_data.get("password")
        if pw:
            return pw
        else:
            old_pw = self.initial.get("password")
            if not old_pw:
                raise ValidationError("A Password is Required")
            return old_pw

    def clean(self):
        """
        try and build a JIRAClient and make a random call to make sure the
        configuration is right.
        """
        cd = self.cleaned_data

        missing_fields = False
        if not cd.get("instance_url"):
            self.errors["instance_url"] = ["Instance URL is required"]
            missing_fields = True
        if not cd.get("username"):
            self.errors["username"] = ["Username is required"]
            missing_fields = True
        if missing_fields:
            raise ValidationError("Missing Fields")

        jira = JIRAClient(cd["instance_url"], cd["username"], cd["password"])
        sut_response = jira.get_priorities()
        if sut_response.status_code == 403 or sut_response.status_code == 401:
            self.errors["username"] = ["Username might be incorrect"]
            self.errors["password"] = ["<PASSWORD>"]
            raise ValidationError("Unable to connect to JIRA: %s, if you have "
                                  "tried and failed multiple times you may have"
                                  " to enter a CAPTCHA in JIRA to re-enable API"
                                  " logins." % sut_response.status_code)
        elif sut_response.status_code == 500 or sut_response.json is None:
            raise ValidationError("Unable to connect to JIRA: Bad Response")
        elif sut_response.status_code > 200:
            raise ValidationError("Unable to connect to JIRA: %s" % sut_response.status_code)

        return cd


class JIRAIssueForm(forms.Form):

    project_key = forms.CharField(widget=forms.HiddenInput())
    project = forms.CharField(widget=forms.HiddenInput())
    issuetype = forms.ChoiceField(
        label="Issue Type",
        help_text="Changing the issue type will refresh the page with the required form fields."
    )

    summary = forms.CharField(
        label=_("Issue Summary"),
        widget=forms.TextInput(attrs={'class': 'span6'})
    )
    description = forms.CharField(
        widget=forms.Textarea(attrs={"class": 'span6'})
    )
    fixVersions = forms.MultipleChoiceField(
        label=_("Fix Version/s"),
        required=False
    )

    def __init__(self, *args, **kwargs):
{'fraction_non_alphanumeric': 0.10879744943708279, 'fraction_numerical': 0.005380093653482116, 'mean_word_length': 2.394656746702739, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4970651', 'n_tokens_mistral': 2828, 'n_tokens_neox': 2745, 'n_words': 757}