-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresult_context.cr
More file actions
94 lines (78 loc) · 2.93 KB
/
result_context.cr
File metadata and controls
94 lines (78 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require "ecr"
require "./base_context"
require "../../models/analysis"
require "../../services/tokei_service"
require "json"
require "uri"
module Tokei::Api::Views::Contexts
# Context for results page
class ResultContext < BaseContext
property analysis : Tokei::Api::Models::Analysis
property result_json : JSON::Any
# Badge types
enum BadgeType
Lines
Language
Languages
Ratio
end
def initialize(@analysis, @result_json, @error_message = nil)
super(@error_message)
end
# Check if the repository URL is from GitHub
def github_repo?
Tokei::Api::Services::TokeiService.github_repo?(@analysis.repo_url)
end
# Extract GitHub owner and repo name
def github_info
Tokei::Api::Services::TokeiService.extract_github_info(@analysis.repo_url)
end
# Generate badge URL for the specified type
def badge_url(type : BadgeType) : String
base_url = server_base_url
if github_repo? && (info = github_info)
owner, repo = info
badge_path = "#{base_url}/badge/github/#{owner}/#{repo}/#{type.to_s.downcase}"
else
badge_path = "#{base_url}/api/badge/#{type.to_s.downcase}?url=#{@analysis.repo_url}"
end
"https://img.shields.io/endpoint?url=#{URI.encode_www_form(badge_path)}"
end
# Generate markdown for badge
def badge_markdown(type : BadgeType, label : String) : String
badge_img = badge_url(type)
if github_repo? && (info = github_info)
owner, repo = info
link_url = "#{server_base_url}/github/#{owner}/#{repo}"
else
link_url = "#{server_base_url}/analyze?url=#{URI.encode_www_form(@analysis.repo_url)}"
end
"[](#{link_url})"
end
# Get link URL for badges
def badge_link_url : String
if github_repo? && (info = github_info)
owner, repo = info
"#{server_base_url}/github/#{owner}/#{repo}"
else
"#{server_base_url}/analyze?url=#{URI.encode_www_form(@analysis.repo_url)}"
end
end
# Get GitHub Next repo-visualization service URL
# This service is part of GitHub Next's Repo Visualization project
# which provides a visual representation of repository structure and relationships.
# For more information, visit: https://githubnext.com/projects/repo-visualization/
def github_next_visualization_url(owner : String, repo : String) : String
"#{ENV["GITHUB_NEXT_VISUALIZATION_URL"]? || "https://mango-dune-07a8b7110.1.azurestaticapps.net"}/?repo=#{owner}%2F#{repo}"
end
# Get GitDiagram service URL for GitHub repositories
def gitdiagram_url(owner : String, repo : String) : String
"https://gitdiagram.com/#{owner}/#{repo}"
end
# Get DeepWiki server URL for GitHub repositories
def deepwiki_url(owner : String, repo : String) : String
"https://deepwiki.com/#{owner}/#{repo}"
end
ECR.def_to_s "#{__DIR__}/../../views/result.ecr"
end
end