<commit_before>from gh import ObjectType, IssueRepo, HasLabel, AddLabel
from datetime import datetime
from .policy import Policy

class StaleIssuePolicy(Policy):
    def __init__(self):
        super().__init__()
        self.stale_days = self.config.get('stale_days')
        self.ignore_lifecycle_label = self.config.get('ignore_lifecycle_label', 'no-lifecycle')
        self.count = 0
        if not self.stale_days:
            self.stale_days = 45

    def applies(self, o):
        return ObjectType(o) == 'issue'

    def apply(self, g, o):
        days_since_created = None
        days_since_updated = None
        now = datetime.now()
        if o.state == 'closed':
            return

        if o.created_at is not None:
            days_since_created = (now - o.created_at).days
        else:
            return

        if days_since_created < self.stale_days:
            return

        if o.updated_at is not None:
            days_since_updated = (now - o.updated_at).days
        else:
            return

        if days_since_updated < self.stale_days:
            return

        if HasLabel(o, self.ignore_lifecycle_label):
            return

        if HasLabel(o, 'to-be-closed'):
            o.create_comment("This issue is tagged as 'to-be-closed' and hasn't been updated " + 
                " in {} days, ".format(days_since_updated) + 
                "so we are closing it. You can always reopen this issue if needed.")
            o.edit(state='closed')
        elif HasLabel(o, 'stale'):
            o.create_comment("This issue is tagged as 'stale' and hasn't been updated " + 
                " in {} days, ".format(days_since_updated) + 
                "so we are tagging it as 'to-be-closed'. It will be closed " +
                "in {} days unless updates are made. ".format(self.stale_days) +
                "If you want to remove this label, comment:\n\n" +
                "> @spinnakerbot remove-label to-be-closed")
            AddLabel(g, o, 'to-be-closed')
        else:
            o.create_comment("This issue hasn't been updated in {} days, ".format(days_since_updated) + 
                "so we are tagging it as 'stale'. If you want to remove this label, comment:\n\n" +
                "> @spinnakerbot remove-label stale")
            AddLabel(g, o, 'stale')

StaleIssuePolicy()<commit_msg>feat(spinbot): do not mark beginner-friendly issues as stale (#5033)<commit_after>from gh import ObjectType, IssueRepo, HasLabel, AddLabel
from datetime import datetime
from .policy import Policy

class StaleIssuePolicy(Policy):
    def __init__(self):
        super().__init__()
        self.stale_days = self.config.get('stale_days')
        self.ignore_lifecycle_label = self.config.get('ignore_lifecycle_label', 'no-lifecycle')
        self.beginner_friendly_label = self.config.get('beginner-friendly_label', 'beginner-friendly')
        self.count = 0
        if not self.stale_days:
            self.stale_days = 45

    def applies(self, o):
        return ObjectType(o) == 'issue'

    def apply(self, g, o):
        days_since_created = None
        days_since_updated = None
        now = datetime.now()
        if o.state == 'closed':
            return

        if o.created_at is not None:
            days_since_created = (now - o.created_at).days
        else:
            return

        if days_since_created < self.stale_days:
            return

        if o.updated_at is not None:
            days_since_updated = (now - o.updated_at).days
        else:
            return

        if days_since_updated < self.stale_days:
            return

        if HasLabel(o, self.ignore_lifecycle_label) or HasLabel(o, self.beginner_friendly_label):
            return

        if HasLabel(o, 'to-be-closed'):
            o.create_comment("This issue is tagged as 'to-be-closed' and hasn't been updated " + 
                " in {} days, ".format(days_since_updated) + 
                "so we are closing it. You can always reopen this issue if needed.")
            o.edit(state='closed')
        elif HasLabel(o, 'stale'):
            o.create_comment("This issue is tagged as 'stale' and hasn't been updated " + 
                " in {} days, ".format(days_since_updated) + 
                "so we are tagging it as 'to-be-closed'. It will be closed " +
                "in {} days unless updates are made. ".format(self.stale_days) +
                "If you want to remove this label, comment:\n\n" +
                "> @spinnakerbot remove-label to-be-closed")
            AddLabel(g, o, 'to-be-closed')
        else:
            o.create_comment("This issue hasn't been updated in {} days, ".format(days_since_updated) + 
                "so we are tagging it as 'stale'. If you want to remove this label, comment:\n\n" +
                "> @spinnakerbot remove-label stale")
            AddLabel(g, o, 'stale')

StaleIssuePolicy()
{'fraction_non_alphanumeric': 0.10251174188278538, 'fraction_numerical': 0.0020420665713702267, 'mean_word_length': 2.029066171923315, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6871051', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1399, 'n_words': 399}