<commit_before># encoding: utf-8
#--
#   Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU Affero General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU Affero General Public License for more details.
#
#   You should have received a copy of the GNU Affero General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#++
module EventRenderingHelper
  def render_event_create_project(event)
    action = action_for_event(:event_status_created) do 
      link_to h(event.target.title), project_path(event.target)
    end
    body = truncate(event.target.stripped_description, :length => 100)
    category = "project"
    [action, body, category]
  end
  
  def render_event_delete_project(event)
    action = action_for_event(:event_status_deleted){ h(event.data) }
    category = "project"
    [action, "", category]
  end
  
  def render_event_update_project(event)
    action = action_for_event(:event_status_updated) do
      link_to h(event.target.title), project_path(event.target)
    end
    category = "project"
    [action, "", category]
  end
  
  def render_event_update_repository(event)
    action = action_for_event(:event_updated_repository) do
      link_to(h(event.target.url_path), 
        repo_owner_path(event.target, :project_repository_path, event.target.project, event.target))
    end
    category = 'repository'
    [action, event.body, category]
  end
  
  def render_event_clone_repository(event)
    original_repo = Repository.find_by_id(event.data.to_i)
    return ["", "", ""] if original_repo.nil?
    
    project = event.target.project
    
    action = action_for_event(:event_status_cloned) do
      link_to(h(original_repo.url_path), repo_owner_path(original_repo, [project, original_repo]))
    end
    body = "New repository is in " + link_to(h(event.target.name), repo_owner_path(event.target, [project, event.target]))
    category = "repository"
    [action, body, category]
  end
  
  def render_event_delete_repository(event)
    action = action_for_event(:event_status_deleted) do
      link_to(h(event.target.title), event.target) + "/" + h(event.data)
    end
    category = "project"
    [action, "", category]
  end
  
  def render_event_commit(event)
    project = event.project
    repo = event.target
    
    case repo.kind
    when Repository::KIND_WIKI
      action = action_for_event(:event_status_push_wiki) do
        "to " + link_to(h(project.slug), project_path(project)) + 
        "/" + link_to(h(t("views.layout.pages")), project_pages_url(project))
      end
      body = h(truncate(event.body, :length => 150))
      category = "wiki"
    when 'commit'
      action = action_for_event(:event_status_committed) do
        link_to(event.data[0,8], project_repository_commit_path(project, repo, event.data)) + 
        " to " + link_to(h(project.slug), project)
      end
      body = link_to(h(truncate(event.body, :length => 150)), 
              project_repository_commit_path(project, repo, event.data))
      category = "commit"
    else
      action = action_for_event(:event_status_committed) do
        link_to(h(event.data[0,8]), repo_owner_path(repo, :project_repository_commit_path, project, repo, event.data)) +
        " to " + link_to(h(project.slug), project)
      end
      body = link_to(h(truncate(event.body, :length => 150)), project_repository_commit_path(project, repo, event.data))
      category = "commit"
    end
    
    [action, body, category]
  end
  
  def render_event_create_branch(event)
    project = event.target.project
    if event.data == "master"
      action = action_for_event(:event_status_started) do
        "of " + link_to(h(project.slug), project_path(project)) + "/" + 
        link_to(h(event.target.name), project_repository_url(project, event.target))
      end
      body = h(event.body)
    else
      action = action_for_event(:event_branch_created) do
        link_to(h(event.data),
          repo_owner_path(event.target, :project_repository_commits_in_ref_path,
            project, event.target, ensplat_path(event.data))) +
        " on " + link_to(h(project.slug), project_path(project)) + "/" +
        link_to(h(event.target.name),
          repo_owner_path(event.target, :project_repository_url, project, event.target))
      end
    end
    category = "commit"
    [action, "", category]
  end
  
  def render_event_delete_branch(event)
    project = event.target.project
    action = action_for_event(:event_branch_deleted) do 
      h(event.data)  + " on " + link_to(h(project.slug), project_path(project)) + 
      "/" + link_to(h(event.target.name),
              repo_owner_path(event.target, :project_repository_url, project, event.target))
    end
    category = "commit"
    [action, "", category]
  end
  
  def render_event_create_tag(event)
    project = event.target.project
    action = action_for_event(:event_tagged) do
      link_to(h(project.slug), project_path(project))  + "/" + 
      link_to(h(event.target.name), project_repository_url(project, event.target))
    end
    body = link_to(h(event.data) + ": " + h(event.body), project_repository_commit_path(project, event.target, h(event.data)))
    category = "commit"
    [action, body, category]
  end
  
  def render_event_delete_tag(event)
    action = action_for_event(:event_tag_deleted) do
      h(event.data) + " on " + link_to(h(event.project.slug), project_path(event.project)) + 
      "/" + link_to(h(event.target.name), @template.project_repository_url(event.project, event.target))
    end
    category = "commit"
    [action, "", category]
  end
  
  def render_event_add_committer(event)
    repo = event.target.is_a?(Repository) ? event.target : event.target.repository
    action = action_for_event(:event_committer_added, :committer => h(event.data)) do
      " to " + link_to(repo_title(repo, event.project), repo_owner_path(repo, [repo.project, repo]))
    end
    category = "repository"
    [action, "", category]
  end
  
  def render_event_remove_committer(event)
    repo = event.target
    action = action_for_event(:event_committer_removed, :committer => h(event.data)) do
      " from " + link_to(repo_title(repo, event.project), repo_owner_path(repo, [repo.project, repo]))
    end
    category = "repository"
    [action, "", category]
  end
  
  def render_event_comment(event)
    comment = Comment.find(event.data)
    
    if event.body == "MergeRequest"
      repo = event.target.target_repository
      project = repo.project
    else
      project = event.target.project
      repo = event.target
    end
    
    if comment.applies_to_merge_request? || comment.applies_to_line_numbers?
      if event.body == "MergeRequest"
        action = action_for_event(:event_commented) do
          " on merge request " +  link_to(h(repo.url_path) +
            " " + h("##{event.target.to_param}"),<commit_msg>Link to the comment with the sha on inline commit comments<commit_after># encoding: utf-8
#--
#   Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU Affero General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU Affero General Public License for more details.
#
#   You should have received a copy of the GNU Affero General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#++
module EventRenderingHelper
  def render_event_create_project(event)
    action = action_for_event(:event_status_created) do 
      link_to h(event.target.title), project_path(event.target)
    end
    body = truncate(event.target.stripped_description, :length => 100)
    category = "project"
    [action, body, category]
  end
  
  def render_event_delete_project(event)
    action = action_for_event(:event_status_deleted){ h(event.data) }
    category = "project"
    [action, "", category]
  end
  
  def render_event_update_project(event)
    action = action_for_event(:event_status_updated) do
      link_to h(event.target.title), project_path(event.target)
    end
    category = "project"
    [action, "", category]
  end
  
  def render_event_update_repository(event)
    action = action_for_event(:event_updated_repository) do
      link_to(h(event.target.url_path), 
        repo_owner_path(event.target, :project_repository_path, event.target.project, event.target))
    end
    category = 'repository'
    [action, event.body, category]
  end
  
  def render_event_clone_repository(event)
    original_repo = Repository.find_by_id(event.data.to_i)
    return ["", "", ""] if original_repo.nil?
    
    project = event.target.project
    
    action = action_for_event(:event_status_cloned) do
      link_to(h(original_repo.url_path), repo_owner_path(original_repo, [project, original_repo]))
    end
    body = "New repository is in " + link_to(h(event.target.name), repo_owner_path(event.target, [project, event.target]))
    category = "repository"
    [action, body, category]
  end
  
  def render_event_delete_repository(event)
    action = action_for_event(:event_status_deleted) do
      link_to(h(event.target.title), event.target) + "/" + h(event.data)
    end
    category = "project"
    [action, "", category]
  end
  
  def render_event_commit(event)
    project = event.project
    repo = event.target
    
    case repo.kind
    when Repository::KIND_WIKI
      action = action_for_event(:event_status_push_wiki) do
        "to " + link_to(h(project.slug), project_path(project)) + 
        "/" + link_to(h(t("views.layout.pages")), project_pages_url(project))
      end
      body = h(truncate(event.body, :length => 150))
      category = "wiki"
    when 'commit'
      action = action_for_event(:event_status_committed) do
        link_to(event.data[0,8], project_repository_commit_path(project, repo, event.data)) + 
        " to " + link_to(h(project.slug), project)
      end
      body = link_to(h(truncate(event.body, :length => 150)), 
              project_repository_commit_path(project, repo, event.data))
      category = "commit"
    else
      action = action_for_event(:event_status_committed) do
        link_to(h(event.data[0,8]), repo_owner_path(repo, :project_repository_commit_path, project, repo, event.data)) +
        " to " + link_to(h(project.slug), project)
      end
      body = link_to(h(truncate(event.body, :length => 150)), project_repository_commit_path(project, repo, event.data))
      category = "commit"
    end
    
    [action, body, category]
  end
  
  def render_event_create_branch(event)
    project = event.target.project
    if event.data == "master"
      action = action_for_event(:event_status_started) do
        "of " + link_to(h(project.slug), project_path(project)) + "/" + 
        link_to(h(event.target.name), project_repository_url(project, event.target))
      end
      body = h(event.body)
    else
      action = action_for_event(:event_branch_created) do
        link_to(h(event.data),
          repo_owner_path(event.target, :project_repository_commits_in_ref_path,
            project, event.target, ensplat_path(event.data))) +
        " on " + link_to(h(project.slug), project_path(project)) + "/" +
        link_to(h(event.target.name),
          repo_owner_path(event.target, :project_repository_url, project, event.target))
      end
    end
    category = "commit"
    [action, "", category]
  end
  
  def render_event_delete_branch(event)
    project = event.target.project
    action = action_for_event(:event_branch_deleted) do 
      h(event.data)  + " on " + link_to(h(project.slug), project_path(project)) + 
      "/" + link_to(h(event.target.name),
              repo_owner_path(event.target, :project_repository_url, project, event.target))
    end
    category = "commit"
    [action, "", category]
  end
  
  def render_event_create_tag(event)
    project = event.target.project
    action = action_for_event(:event_tagged) do
      link_to(h(project.slug), project_path(project))  + "/" + 
      link_to(h(event.target.name), project_repository_url(project, event.target))
    end
    body = link_to(h(event.data) + ": " + h(event.body), project_repository_commit_path(project, event.target, h(event.data)))
    category = "commit"
    [action, body, category]
  end
  
  def render_event_delete_tag(event)
    action = action_for_event(:event_tag_deleted) do
      h(event.data) + " on " + link_to(h(event.project.slug), project_path(event.project)) + 
      "/" + link_to(h(event.target.name), @template.project_repository_url(event.project, event.target))
    end
    category = "commit"
    [action, "", category]
  end
  
  def render_event_add_committer(event)
    repo = event.target.is_a?(Repository) ? event.target : event.target.repository
    action = action_for_event(:event_committer_added, :committer => h(event.data)) do
      " to " + link_to(repo_title(repo, event.project), repo_owner_path(repo, [repo.project, repo]))
    end
    category = "repository"
    [action, "", category]
  end
  
  def render_event_remove_committer(event)
    repo = event.target
    action = action_for_event(:event_committer_removed, :committer => h(event.data)) do
      " from " + link_to(repo_title(repo, event.project), repo_owner_path(repo, [repo.project, repo]))
    end
    category = "repository"
    [action, "", category]
  end
  
  def render_event_comment(event)
    comment = Comment.find(event.data)
    
    if event.body == "MergeRequest"
      repo = event.target.target_repository
      project = repo.project
    else
      project = event.target.project
      repo = event.target
    end
    
    if comment.applies_to_merge_request? || MergeRequestVersion === comment.target
      if event.body == "MergeRequest"
        action = action_for_event(:event_commented) do
          " on merge request " +  link_to(h(repo.url_path) +
            " " + h("##{event.target.to_param}"),
{'fraction_non_alphanumeric': 0.11474179684835255, 'fraction_numerical': 0.0030015690019783068, 'mean_word_length': 3.498312365756367, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 17, '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': '3382660', 'n_tokens_mistral': 4693, 'n_tokens_neox': 4649, 'n_words': 970}