<commit_before>
# Copyright 2016 Battelle Energy Alliance, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import unicode_literals, absolute_import
from ci import models, Permissions, event
from django.urls import reverse
import traceback
import logging
logger = logging.getLogger('ci')

class PullRequestEvent(object):
    """
    Hold all the data that will go into a Event of
    a Pull Request type. Will create and save the DB tables.
    The creator of this object will need to set the following:
      pr_number: The PR number
      title: The title of the PR
      action: The action that is happening on the PR. One of the corresponding class variables.
      base_commit : GitCommitData of the base sha
      head_commit : GitCommitData of the head sha
      comments_url : Url to the comments
      review_comments_url : Url to the review comments
      html_url : Http URL to the repo
      full_text : All the payload data
      build_user : GitUser corresponding to the build user
      trigger_user: Text of user who triggered this PR
      description : Description of the push, ie "Merge commit blablabla"
    """
    OPENED = 0
    CLOSED = 1
    REOPENED = 2
    SYNCHRONIZE = 3

    def __init__(self):
        self.pr_number = None
        self.action = None
        self.build_user = None
        self.base_commit = None
        self.head_commit = None
        self.title = None
        self.html_url = None
        self.full_text = None
        self.comments_url = None
        self.review_comments_url = None
        self.description = ''
        self.trigger_user = ''
        self.changed_files = []

    def _already_exists(self, base, head):
        try:
            pr = models.PullRequest.objects.get(
                    number=self.pr_number,
                    repository=base.branch.repository)
        except models.PullRequest.DoesNotExist:
            return

        if self.action == self.CLOSED and not pr.closed:
            pr.closed = True
            logger.info('Closed pull request {}: #{} on {}'.format(pr.pk, pr, base.branch))
            pr.save()
<commit_msg>Improve closed PR log message<commit_after>
# Copyright 2016 Battelle Energy Alliance, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import unicode_literals, absolute_import
from ci import models, Permissions, event
from django.urls import reverse
import traceback
import logging
logger = logging.getLogger('ci')

class PullRequestEvent(object):
    """
    Hold all the data that will go into a Event of
    a Pull Request type. Will create and save the DB tables.
    The creator of this object will need to set the following:
      pr_number: The PR number
      title: The title of the PR
      action: The action that is happening on the PR. One of the corresponding class variables.
      base_commit : GitCommitData of the base sha
      head_commit : GitCommitData of the head sha
      comments_url : Url to the comments
      review_comments_url : Url to the review comments
      html_url : Http URL to the repo
      full_text : All the payload data
      build_user : GitUser corresponding to the build user
      trigger_user: Text of user who triggered this PR
      description : Description of the push, ie "Merge commit blablabla"
    """
    OPENED = 0
    CLOSED = 1
    REOPENED = 2
    SYNCHRONIZE = 3

    def __init__(self):
        self.pr_number = None
        self.action = None
        self.build_user = None
        self.base_commit = None
        self.head_commit = None
        self.title = None
        self.html_url = None
        self.full_text = None
        self.comments_url = None
        self.review_comments_url = None
        self.description = ''
        self.trigger_user = ''
        self.changed_files = []

    def _already_exists(self, base, head):
        try:
            pr = models.PullRequest.objects.get(
                    number=self.pr_number,
                    repository=base.branch.repository)
        except models.PullRequest.DoesNotExist:
            return

        if self.action == self.CLOSED and not pr.closed:
            pr.closed = True
            logger.info('{}: Closed pull request {}: {}'.format(base.branch, pr.pk, pr))
            pr.save()

{'fraction_non_alphanumeric': 0.06488332384746727, 'fraction_numerical': 0.004553215708594195, 'mean_word_length': 2.576662143826323, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '882879', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1381, 'n_words': 574}