gitem 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +8 -0
- data/exe/gitem +21 -0
- data/lib/gitem/index.html.erb +429 -0
- data/lib/gitem/version.rb +5 -0
- data/lib/gitem.rb +250 -0
- data/sig/gitem.rbs +4 -0
- metadata +122 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5b9c3b4254111162f1b7f4c01d02a2bfaf7f6dd72d2b74917dd3afbb26da56c8
|
|
4
|
+
data.tar.gz: 03d052e30428e19d8d8613a6fd0d413c3c2e758acb0fcb9de8e8d239539f582d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 10a23da9cfb7d80aaf1ef0b18aeb1d23bc8ebb8524b53b03baec012c9d13025e1c593131ae23d46afccdd2a073644aff871ba5d0ed7c25486a16ef3fe45528bc
|
|
7
|
+
data.tar.gz: 54475cf8d4c94e44b2f8c5aa9ffc231d54bfad666f371166aff2fd250c9a0d3aaa08b8a793b9027f0530259b34c879705603770a448d885bd7429f7c3c7b39c9
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 mo khan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Gitem
|
|
2
|
+
|
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
|
4
|
+
|
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gitem`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
|
10
|
+
|
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/xlgmokha/gitem.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/exe/gitem
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "gitem"
|
|
5
|
+
|
|
6
|
+
if ARGV.empty?
|
|
7
|
+
puts "Usage: ruby #{$0} <path-to-git-repo> [output-directory]"
|
|
8
|
+
puts "Default output: <repo>/.git/srv/"
|
|
9
|
+
puts "Example: ruby #{$0} ."
|
|
10
|
+
exit 1
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
repo_path = ARGV[0]
|
|
14
|
+
output_dir = ARGV[1]
|
|
15
|
+
|
|
16
|
+
unless File.exist?(File.join(repo_path, '.git')) || File.exist?(File.join(repo_path, 'HEAD'))
|
|
17
|
+
puts "Error: #{repo_path} is not a valid git repository"
|
|
18
|
+
exit 1
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
Gitem::GitToJson.new(repo_path, output_dir).export!
|
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Git Browser</title>
|
|
7
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/9.1.6/marked.min.js"></script>
|
|
8
|
+
<style>
|
|
9
|
+
:root{--color-canvas-default:#0d1117;--color-canvas-subtle:#161b22;--color-canvas-inset:#010409;--color-border-default:#30363d;--color-border-muted:#21262d;--color-fg-default:#e6edf3;--color-fg-muted:#8b949e;--color-fg-subtle:#6e7681;--color-accent-fg:#2f81f7;--color-accent-emphasis:#1f6feb;--color-success-fg:#3fb950;--color-danger-fg:#f85149;--color-attention-fg:#d29922;--color-btn-bg:#21262d;--color-btn-border:#363b42;--color-btn-hover-bg:#30363d}
|
|
10
|
+
*{box-sizing:border-box;margin:0;padding:0}
|
|
11
|
+
body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",Helvetica,Arial,sans-serif;font-size:14px;line-height:1.5;color:var(--color-fg-default);background:var(--color-canvas-default)}
|
|
12
|
+
a{color:var(--color-accent-fg);text-decoration:none}a:hover{text-decoration:underline}
|
|
13
|
+
.container{max-width:1280px;margin:0 auto;padding:0 32px}
|
|
14
|
+
.AppHeader{background:var(--color-canvas-subtle);border-bottom:1px solid var(--color-border-default);padding:16px 0}
|
|
15
|
+
.AppHeader-logo{display:flex;align-items:center;gap:8px}
|
|
16
|
+
.AppHeader-logo svg{fill:var(--color-fg-default)}
|
|
17
|
+
.AppHeader-context{display:flex;align-items:center;gap:8px;font-size:16px}
|
|
18
|
+
.UnderlineNav{border-bottom:1px solid var(--color-border-default);margin-bottom:16px}
|
|
19
|
+
.UnderlineNav-body{display:flex;gap:8px;margin-bottom:-1px}
|
|
20
|
+
.UnderlineNav-item{padding:8px 16px;color:var(--color-fg-default);border-bottom:2px solid transparent;display:flex;align-items:center;gap:8px}
|
|
21
|
+
.UnderlineNav-item:hover{text-decoration:none;border-bottom-color:var(--color-border-muted)}
|
|
22
|
+
.UnderlineNav-item.selected{font-weight:600;border-bottom-color:var(--color-attention-fg)}
|
|
23
|
+
.Counter{background:var(--color-btn-bg);border-radius:10px;padding:0 6px;font-size:12px;font-weight:500;min-width:20px;text-align:center}
|
|
24
|
+
.Box{border:1px solid var(--color-border-default);border-radius:6px;background:var(--color-canvas-subtle)}
|
|
25
|
+
.Box-header{padding:16px;border-bottom:1px solid var(--color-border-default);display:flex;align-items:center;justify-content:space-between;background:var(--color-canvas-subtle)}
|
|
26
|
+
.Box-row{padding:8px 16px;border-bottom:1px solid var(--color-border-default);display:flex;align-items:center}
|
|
27
|
+
.Box-row:last-child{border-bottom:none}
|
|
28
|
+
.Box-row:hover{background:var(--color-canvas-inset)}
|
|
29
|
+
.file-wrap{margin-top:16px}
|
|
30
|
+
.branch-select{display:flex;align-items:center;gap:16px;margin-bottom:16px;flex-wrap:wrap}
|
|
31
|
+
.btn{background:var(--color-btn-bg);border:1px solid var(--color-btn-border);border-radius:6px;padding:5px 16px;color:var(--color-fg-default);font-size:14px;cursor:pointer;display:inline-flex;align-items:center;gap:8px}
|
|
32
|
+
.btn:hover{background:var(--color-btn-hover-bg)}
|
|
33
|
+
.btn-primary{background:var(--color-accent-emphasis);border-color:var(--color-accent-emphasis)}
|
|
34
|
+
.btn-primary:hover{background:#388bfd}
|
|
35
|
+
.dropdown{position:relative;display:inline-block}
|
|
36
|
+
.dropdown-menu{position:absolute;top:100%;left:0;z-index:100;min-width:300px;max-height:400px;overflow-y:auto;background:var(--color-canvas-subtle);border:1px solid var(--color-border-default);border-radius:6px;box-shadow:0 8px 24px rgba(0,0,0,.4);display:none;margin-top:4px}
|
|
37
|
+
.dropdown-menu.show{display:block}
|
|
38
|
+
.dropdown-header{padding:8px 16px;font-weight:600;border-bottom:1px solid var(--color-border-default)}
|
|
39
|
+
.dropdown-item{padding:8px 16px;cursor:pointer;display:flex;align-items:center;gap:8px}
|
|
40
|
+
.dropdown-item:hover{background:var(--color-accent-emphasis)}
|
|
41
|
+
.dropdown-item .check{opacity:0;width:16px}
|
|
42
|
+
.dropdown-item.selected .check{opacity:1}
|
|
43
|
+
.octicon{display:inline-block;vertical-align:text-bottom;fill:currentColor}
|
|
44
|
+
.icon-directory{color:var(--color-accent-fg)}
|
|
45
|
+
.icon-file{color:var(--color-fg-muted)}
|
|
46
|
+
.file-name{flex:1;margin-left:8px}
|
|
47
|
+
.file-commit{color:var(--color-fg-muted);flex:2;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:left}
|
|
48
|
+
.file-time{color:var(--color-fg-muted);min-width:100px;text-align:right}
|
|
49
|
+
.readme-box{margin-top:16px}
|
|
50
|
+
.readme-header{padding:10px 16px;font-weight:600;display:flex;align-items:center;gap:8px;border-bottom:1px solid var(--color-border-default)}
|
|
51
|
+
.markdown-body{padding:32px;background:var(--color-canvas-default)}
|
|
52
|
+
.markdown-body h1,.markdown-body h2{padding-bottom:.3em;border-bottom:1px solid var(--color-border-default);margin-top:24px;margin-bottom:16px}
|
|
53
|
+
.markdown-body h1{font-size:2em}.markdown-body h2{font-size:1.5em}.markdown-body h3{font-size:1.25em}
|
|
54
|
+
.markdown-body p{margin-bottom:16px}
|
|
55
|
+
.markdown-body code{background:var(--color-btn-bg);padding:.2em .4em;border-radius:6px;font-family:ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,monospace;font-size:85%}
|
|
56
|
+
.markdown-body pre{background:var(--color-canvas-subtle);padding:16px;border-radius:6px;overflow-x:auto;margin-bottom:16px}
|
|
57
|
+
.markdown-body pre code{background:none;padding:0}
|
|
58
|
+
.markdown-body ul,.markdown-body ol{padding-left:2em;margin-bottom:16px}
|
|
59
|
+
.markdown-body li{margin-bottom:4px}
|
|
60
|
+
.markdown-body a{color:var(--color-accent-fg)}
|
|
61
|
+
.markdown-body blockquote{padding:0 1em;color:var(--color-fg-muted);border-left:4px solid var(--color-border-default);margin-bottom:16px}
|
|
62
|
+
.markdown-body img{max-width:100%}
|
|
63
|
+
.markdown-body table{border-collapse:collapse;margin-bottom:16px;width:100%}
|
|
64
|
+
.markdown-body th,.markdown-body td{border:1px solid var(--color-border-default);padding:6px 13px}
|
|
65
|
+
.markdown-body th{background:var(--color-canvas-subtle)}
|
|
66
|
+
.blob-code{padding:0;overflow-x:auto}
|
|
67
|
+
.blob-code table{width:100%;border-collapse:collapse;font-family:ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,monospace;font-size:12px}
|
|
68
|
+
.blob-code td{padding:0 10px;line-height:20px;vertical-align:top}
|
|
69
|
+
.blob-num{width:1%;min-width:50px;text-align:right;color:var(--color-fg-subtle);user-select:none;padding-right:10px;background:var(--color-canvas-subtle);border-right:1px solid var(--color-border-default)}
|
|
70
|
+
.blob-content-cell{white-space:pre;padding-left:10px!important}
|
|
71
|
+
.commit-list .Box-row{padding:16px}
|
|
72
|
+
.commit-msg{font-weight:600;margin-bottom:4px}
|
|
73
|
+
.commit-meta{color:var(--color-fg-muted);font-size:12px;display:flex;align-items:center;gap:8px;flex-wrap:wrap}
|
|
74
|
+
.commit-sha{font-family:ui-monospace,SFMono-Regular,monospace;font-size:12px;color:var(--color-accent-fg);background:var(--color-btn-bg);padding:4px 8px;border-radius:6px;border:1px solid var(--color-btn-border)}
|
|
75
|
+
.commit-sha:hover{background:var(--color-btn-hover-bg);text-decoration:none}
|
|
76
|
+
.avatar{width:20px;height:20px;border-radius:50%;background:var(--color-btn-bg)}
|
|
77
|
+
.diff-stat{display:flex;align-items:center;gap:4px;font-size:12px}
|
|
78
|
+
.diff-stat .add{color:var(--color-success-fg)}.diff-stat .del{color:var(--color-danger-fg)}
|
|
79
|
+
.tag{display:inline-flex;align-items:center;gap:4px;background:var(--color-accent-emphasis);color:#fff;padding:2px 8px;border-radius:16px;font-size:12px;font-weight:500}
|
|
80
|
+
.breadcrumb{display:flex;align-items:center;gap:4px;margin-bottom:16px}
|
|
81
|
+
.breadcrumb-item{color:var(--color-accent-fg)}
|
|
82
|
+
.breadcrumb-sep{color:var(--color-fg-muted)}
|
|
83
|
+
.empty-state{padding:64px;text-align:center;color:var(--color-fg-muted)}
|
|
84
|
+
.loading{padding:64px;text-align:center;color:var(--color-fg-muted)}
|
|
85
|
+
.error-banner{background:rgba(248,81,73,.15);border:1px solid var(--color-danger-fg);color:var(--color-danger-fg);padding:16px;border-radius:6px;margin-bottom:16px;display:none}
|
|
86
|
+
.compare-selector{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
|
|
87
|
+
.compare-arrow{color:var(--color-fg-muted);font-size:20px}
|
|
88
|
+
.compare-diff{margin-top:16px}
|
|
89
|
+
.file-diff{margin-bottom:16px}
|
|
90
|
+
.file-diff-header{padding:8px 16px;background:var(--color-canvas-subtle);border-bottom:1px solid var(--color-border-default);display:flex;justify-content:space-between;align-items:center}
|
|
91
|
+
.diff-line{font-family:ui-monospace,monospace;font-size:12px;line-height:20px;white-space:pre}
|
|
92
|
+
.diff-add{background:rgba(63,185,80,.15);color:var(--color-success-fg)}
|
|
93
|
+
.diff-del{background:rgba(248,81,73,.15);color:var(--color-danger-fg)}
|
|
94
|
+
.diff-hunk{background:rgba(56,139,253,.15);color:var(--color-accent-fg)}
|
|
95
|
+
@media(max-width:768px){.container{padding:0 16px}.file-commit,.file-time{display:none}.Box-row{padding:8px 12px}}
|
|
96
|
+
</style>
|
|
97
|
+
</head>
|
|
98
|
+
<body>
|
|
99
|
+
<header class="AppHeader">
|
|
100
|
+
<div class="container">
|
|
101
|
+
<div class="AppHeader-context">
|
|
102
|
+
<svg height="32" viewBox="0 0 16 16" width="32" class="octicon"><path d="M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z"></path></svg>
|
|
103
|
+
<span id="repo-name" style="font-weight:600;font-size:20px">Repository</span>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
</header>
|
|
107
|
+
<div class="container" style="padding-top:24px">
|
|
108
|
+
<nav class="UnderlineNav">
|
|
109
|
+
<div class="UnderlineNav-body" id="nav-tabs"></div>
|
|
110
|
+
</nav>
|
|
111
|
+
<div id="error" class="error-banner"></div>
|
|
112
|
+
<div id="app"><div class="loading">Loading repository...</div></div>
|
|
113
|
+
</div>
|
|
114
|
+
<script>
|
|
115
|
+
const S={repo:null,view:'code',ref:'main',path:'',sha:'',base:'',compare:''};
|
|
116
|
+
const $=id=>document.getElementById(id);
|
|
117
|
+
const h=(t,a={},c=[])=>{const e=document.createElement(t);Object.entries(a).forEach(([k,v])=>k==='text'?e.textContent=v:k==='html'?e.innerHTML=v:k.startsWith('on')?e.addEventListener(k.slice(2).toLowerCase(),v):e.setAttribute(k,v));c.forEach(x=>e.appendChild(typeof x==='string'?document.createTextNode(x):x));return e};
|
|
118
|
+
const svg=(d,w=16)=>`<svg viewBox="0 0 16 16" width="${w}" height="${w}" class="octicon" style="fill:currentColor">${d}</svg>`;
|
|
119
|
+
const icons={
|
|
120
|
+
file:'<path d="M2 1.75C2 .784 2.784 0 3.75 0h6.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v9.586A1.75 1.75 0 0 1 13.25 16h-9.5A1.75 1.75 0 0 1 2 14.25Zm1.75-.25a.25.25 0 0 0-.25.25v12.5c0 .138.112.25.25.25h9.5a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 9 4.25V1.5Zm6.75.062V4.25c0 .138.112.25.25.25h2.688l-.011-.013-2.914-2.914-.013-.011Z"/>',
|
|
121
|
+
dir:'<path d="M1.75 1A1.75 1.75 0 0 0 0 2.75v10.5C0 14.216.784 15 1.75 15h12.5A1.75 1.75 0 0 0 16 13.25v-8.5A1.75 1.75 0 0 0 14.25 3H7.5a.25.25 0 0 1-.2-.1l-.9-1.2C6.07 1.26 5.55 1 5 1H1.75Z"/>',
|
|
122
|
+
branch:'<path d="M9.5 3.25a2.25 2.25 0 1 1 3 2.122V6A2.5 2.5 0 0 1 10 8.5H6a1 1 0 0 0-1 1v1.128a2.251 2.251 0 1 1-1.5 0V5.372a2.25 2.25 0 1 1 1.5 0v1.836A2.493 2.493 0 0 1 6 7h4a1 1 0 0 0 1-1v-.628A2.25 2.25 0 0 1 9.5 3.25Zm-6 0a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0Zm8.25-.75a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5ZM4.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Z"/>',
|
|
123
|
+
tag:'<path d="M1 7.775V2.75C1 1.784 1.784 1 2.75 1h5.025c.464 0 .91.184 1.238.513l6.25 6.25a1.75 1.75 0 0 1 0 2.474l-5.026 5.026a1.75 1.75 0 0 1-2.474 0l-6.25-6.25A1.752 1.752 0 0 1 1 7.775Zm1.5 0c0 .066.026.13.073.177l6.25 6.25a.25.25 0 0 0 .354 0l5.025-5.025a.25.25 0 0 0 0-.354l-6.25-6.25a.25.25 0 0 0-.177-.073H2.75a.25.25 0 0 0-.25.25ZM6 5a1 1 0 1 1 0 2 1 1 0 0 1 0-2Z"/>',
|
|
124
|
+
commit:'<path d="M11.93 8.5a4.002 4.002 0 0 1-7.86 0H.75a.75.75 0 0 1 0-1.5h3.32a4.002 4.002 0 0 1 7.86 0h3.32a.75.75 0 0 1 0 1.5Zm-1.43-.75a2.5 2.5 0 1 0-5 0 2.5 2.5 0 0 0 5 0Z"/>',
|
|
125
|
+
code:'<path d="m11.28 3.22 4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734L13.94 8l-3.72-3.72a.749.749 0 0 1 .326-1.275.749.749 0 0 1 .734.215Zm-6.56 0a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042L2.06 8l3.72 3.72a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215L.47 8.53a.75.75 0 0 1 0-1.06Z"/>',
|
|
126
|
+
compare:'<path d="M4.72.22a.75.75 0 0 1 1.06 0l1 1a.75.75 0 0 1 0 1.06l-1 1a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042l.47-.47H2.5v10.5h1.69l-.47-.47a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018l1 1a.75.75 0 0 1 0 1.06l-1 1a.751.751 0 0 1-1.042.018.751.751 0 0 1-.018-1.042l.47-.47H2.25a.75.75 0 0 1-.75-.75V2.75A.75.75 0 0 1 2.25 2h2.44l-.47-.47a.75.75 0 0 1 0-1.06ZM13.5 2.5v10.5h-1.69l.47.47a.751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018l-1-1a.75.75 0 0 1 0-1.06l1-1a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-.47.47H13.5V2.5h-1.69l.47.47a.751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018l-1-1a.75.75 0 0 1 0-1.06l1-1a.751.751 0 0 1 1.042-.018.751.751 0 0 1 .018 1.042l-.47.47h2.44a.75.75 0 0 1 .75.75Z"/>',
|
|
127
|
+
readme:'<path d="M0 1.75A.75.75 0 0 1 .75 1h4.253c1.227 0 2.317.59 3 1.501A3.743 3.743 0 0 1 11.006 1h4.245a.75.75 0 0 1 .75.75v10.5a.75.75 0 0 1-.75.75h-4.507a2.25 2.25 0 0 0-1.591.659l-.622.621a.75.75 0 0 1-1.06 0l-.622-.621A2.25 2.25 0 0 0 5.258 13H.75a.75.75 0 0 1-.75-.75Zm7.251 10.324.004-5.073-.002-2.253A2.25 2.25 0 0 0 5.003 2.5H1.5v9h3.757a3.75 3.75 0 0 1 1.994.574ZM8.755 4.75l-.004 7.322a3.752 3.752 0 0 1 1.992-.572H14.5v-9h-3.495a2.25 2.25 0 0 0-2.25 2.25Z"/>',
|
|
128
|
+
check:'<path d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"/>',
|
|
129
|
+
down:'<path d="m4.427 7.427 3.396 3.396a.25.25 0 0 0 .354 0l3.396-3.396A.25.25 0 0 0 11.396 7H4.604a.25.25 0 0 0-.177.427Z"/>'
|
|
130
|
+
};
|
|
131
|
+
const timeAgo=d=>{const s=Math.floor((Date.now()-new Date(d))/1000);if(s<60)return'just now';if(s<3600)return Math.floor(s/60)+' min ago';if(s<86400)return Math.floor(s/3600)+' hours ago';if(s<604800)return Math.floor(s/86400)+' days ago';return new Date(d).toLocaleDateString()};
|
|
132
|
+
const esc=s=>s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
|
133
|
+
|
|
134
|
+
async function load(p){const r=await fetch(p);if(!r.ok)throw new Error(`Failed: ${p}`);return r.json()}
|
|
135
|
+
function showError(m){const e=$('error');e.textContent=m;e.style.display='block'}
|
|
136
|
+
function hideError(){$('error').style.display='none'}
|
|
137
|
+
|
|
138
|
+
function renderNav(){
|
|
139
|
+
const nav=$('nav-tabs');nav.innerHTML='';
|
|
140
|
+
const tabs=[['code','Code',icons.code],['commits','Commits',icons.commit],['branches','Branches',icons.branch],['tags','Tags',icons.tag],['compare','Compare',icons.compare]];
|
|
141
|
+
tabs.forEach(([v,t,i])=>{
|
|
142
|
+
const a=h('a',{class:'UnderlineNav-item'+(S.view===v?' selected':''),href:'#'});
|
|
143
|
+
a.innerHTML=svg(i)+' '+t;
|
|
144
|
+
if(v==='branches')a.innerHTML+=` <span class="Counter">${S.repo?.branches_count||0}</span>`;
|
|
145
|
+
if(v==='tags')a.innerHTML+=` <span class="Counter">${S.repo?.tags_count||0}</span>`;
|
|
146
|
+
a.onclick=e=>{e.preventDefault();S.view=v;S.path='';S.sha='';render()};
|
|
147
|
+
nav.appendChild(a);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function branchDropdown(id,selected,onSelect){
|
|
152
|
+
const wrap=h('div',{class:'dropdown'});
|
|
153
|
+
const btn=h('button',{class:'btn',id});
|
|
154
|
+
btn.innerHTML=svg(icons.branch)+` <span>${esc(selected)}</span> `+svg(icons.down);
|
|
155
|
+
const menu=h('div',{class:'dropdown-menu',id:id+'-menu'});
|
|
156
|
+
btn.onclick=()=>menu.classList.toggle('show');
|
|
157
|
+
document.addEventListener('click',e=>{if(!wrap.contains(e.target))menu.classList.remove('show')});
|
|
158
|
+
wrap.append(btn,menu);
|
|
159
|
+
load('branches.json').then(branches=>{
|
|
160
|
+
menu.appendChild(h('div',{class:'dropdown-header',text:'Switch branches'}));
|
|
161
|
+
branches.forEach(b=>{
|
|
162
|
+
const item=h('div',{class:'dropdown-item'+(b.name===selected?' selected':'')});
|
|
163
|
+
item.innerHTML=svg(icons.check,12)+' '+esc(b.name);
|
|
164
|
+
item.querySelector('svg').classList.add('check');
|
|
165
|
+
item.onclick=()=>{onSelect(b.name);menu.classList.remove('show')};
|
|
166
|
+
menu.appendChild(item);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
return wrap;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async function renderCode(){
|
|
173
|
+
const wrap=h('div');
|
|
174
|
+
const branches=await load('branches.json');
|
|
175
|
+
const branch=branches.find(b=>b.name===S.ref)||branches.find(b=>b.is_head)||branches[0];
|
|
176
|
+
if(!branch)return h('div',{class:'empty-state',text:'No branches found'});
|
|
177
|
+
const commit=await load(`commits/${branch.sha}.json`);
|
|
178
|
+
|
|
179
|
+
const top=h('div',{class:'branch-select'});
|
|
180
|
+
top.appendChild(branchDropdown('branch-sel',S.ref,name=>{S.ref=name;S.path='';render()}));
|
|
181
|
+
|
|
182
|
+
const goTo=h('button',{class:'btn',html:svg(icons.commit)+' <span>Go to commit</span>'});
|
|
183
|
+
goTo.onclick=()=>{S.view='commits';render()};
|
|
184
|
+
top.appendChild(goTo);
|
|
185
|
+
wrap.appendChild(top);
|
|
186
|
+
|
|
187
|
+
if(S.path){
|
|
188
|
+
const bc=h('div',{class:'breadcrumb'});
|
|
189
|
+
const root=h('a',{class:'breadcrumb-item',href:'#',text:S.repo.name});
|
|
190
|
+
root.onclick=e=>{e.preventDefault();S.path='';render()};
|
|
191
|
+
bc.appendChild(root);
|
|
192
|
+
const parts=S.path.split('/');
|
|
193
|
+
parts.forEach((p,i)=>{
|
|
194
|
+
bc.appendChild(h('span',{class:'breadcrumb-sep',text:'/'}));
|
|
195
|
+
if(i<parts.length-1){
|
|
196
|
+
const link=h('a',{class:'breadcrumb-item',href:'#',text:p});
|
|
197
|
+
link.onclick=e=>{e.preventDefault();S.path=parts.slice(0,i+1).join('/');render()};
|
|
198
|
+
bc.appendChild(link);
|
|
199
|
+
}else bc.appendChild(h('span',{text:p}));
|
|
200
|
+
});
|
|
201
|
+
wrap.appendChild(bc);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
let tree,isBlob=false,blobEntry=null;
|
|
205
|
+
if(S.path){
|
|
206
|
+
const root=await load(`trees/${commit.tree_sha}.json`);
|
|
207
|
+
const parts=S.path.split('/');
|
|
208
|
+
let current=root;
|
|
209
|
+
for(let i=0;i<parts.length;i++){
|
|
210
|
+
const entry=current.entries.find(e=>e.name===parts[i]);
|
|
211
|
+
if(!entry)return h('div',{class:'empty-state',text:'Path not found'});
|
|
212
|
+
if(entry.type==='blob'){isBlob=true;blobEntry=entry;break}
|
|
213
|
+
current=await load(`trees/${entry.sha}.json`);
|
|
214
|
+
}
|
|
215
|
+
tree=current;
|
|
216
|
+
}else tree=await load(`trees/${commit.tree_sha}.json`);
|
|
217
|
+
|
|
218
|
+
if(isBlob){
|
|
219
|
+
const blob=await load(`blobs/${blobEntry.sha}.json`);
|
|
220
|
+
const box=h('div',{class:'Box'});
|
|
221
|
+
const header=h('div',{class:'Box-header'});
|
|
222
|
+
header.innerHTML=`<span>${esc(blobEntry.name)}</span><span style="color:var(--color-fg-muted)">${blob.size} bytes</span>`;
|
|
223
|
+
box.appendChild(header);
|
|
224
|
+
if(blob.binary){
|
|
225
|
+
box.appendChild(h('div',{class:'empty-state',text:'Binary file not shown'}));
|
|
226
|
+
}else{
|
|
227
|
+
const code=h('div',{class:'blob-code'});
|
|
228
|
+
const tbl=h('table');
|
|
229
|
+
(blob.content||'').split('\n').forEach((line,i)=>{
|
|
230
|
+
const tr=h('tr');
|
|
231
|
+
tr.innerHTML=`<td class="blob-num">${i+1}</td><td class="blob-content-cell">${esc(line)}</td>`;
|
|
232
|
+
tbl.appendChild(tr);
|
|
233
|
+
});
|
|
234
|
+
code.appendChild(tbl);
|
|
235
|
+
box.appendChild(code);
|
|
236
|
+
}
|
|
237
|
+
wrap.appendChild(box);
|
|
238
|
+
return wrap;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const box=h('div',{class:'Box'});
|
|
242
|
+
const header=h('div',{class:'Box-header'});
|
|
243
|
+
header.innerHTML=`<span><strong>${esc(commit.author.name)}</strong> ${esc(commit.message_headline)}</span><a href="#" class="commit-sha">${commit.short_sha}</a>`;
|
|
244
|
+
header.querySelector('.commit-sha').onclick=e=>{e.preventDefault();S.view='commit';S.sha=commit.sha;render()};
|
|
245
|
+
box.appendChild(header);
|
|
246
|
+
|
|
247
|
+
const sorted=[...tree.entries].sort((a,b)=>a.type===b.type?a.name.localeCompare(b.name):a.type==='tree'?-1:1);
|
|
248
|
+
if(S.path){
|
|
249
|
+
const up=h('div',{class:'Box-row',style:'cursor:pointer'});
|
|
250
|
+
up.innerHTML=`<span class="icon-directory">${svg(icons.dir)}</span><span class="file-name">..</span>`;
|
|
251
|
+
up.onclick=()=>{S.path=S.path.split('/').slice(0,-1).join('/');render()};
|
|
252
|
+
box.appendChild(up);
|
|
253
|
+
}
|
|
254
|
+
sorted.forEach(e=>{
|
|
255
|
+
const row=h('div',{class:'Box-row',style:'cursor:pointer'});
|
|
256
|
+
const icon=e.type==='tree'?`<span class="icon-directory">${svg(icons.dir)}</span>`:`<span class="icon-file">${svg(icons.file)}</span>`;
|
|
257
|
+
row.innerHTML=`${icon}<span class="file-name">${esc(e.name)}</span><span class="file-commit"></span><span class="file-time"></span>`;
|
|
258
|
+
row.onclick=()=>{S.path=e.path;render()};
|
|
259
|
+
box.appendChild(row);
|
|
260
|
+
});
|
|
261
|
+
wrap.appendChild(box);
|
|
262
|
+
|
|
263
|
+
if(!S.path&&S.repo.readme){
|
|
264
|
+
const readme=h('div',{class:'Box readme-box'});
|
|
265
|
+
const rh=h('div',{class:'readme-header'});
|
|
266
|
+
rh.innerHTML=svg(icons.readme)+' '+esc(S.repo.readme_name||'README.md');
|
|
267
|
+
readme.appendChild(rh);
|
|
268
|
+
const md=h('div',{class:'markdown-body'});
|
|
269
|
+
md.innerHTML=marked.parse(S.repo.readme);
|
|
270
|
+
readme.appendChild(md);
|
|
271
|
+
wrap.appendChild(readme);
|
|
272
|
+
}
|
|
273
|
+
return wrap;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async function renderCommits(){
|
|
277
|
+
const commits=await load('commits.json');
|
|
278
|
+
const wrap=h('div');
|
|
279
|
+
wrap.appendChild(branchDropdown('commits-branch',S.ref,name=>{S.ref=name;render()}));
|
|
280
|
+
const box=h('div',{class:'Box commit-list',style:'margin-top:16px'});
|
|
281
|
+
commits.forEach(c=>{
|
|
282
|
+
const row=h('div',{class:'Box-row',style:'display:block'});
|
|
283
|
+
const msg=h('a',{class:'commit-msg',href:'#',text:c.message_headline});
|
|
284
|
+
msg.onclick=e=>{e.preventDefault();S.view='commit';S.sha=c.sha;render()};
|
|
285
|
+
const meta=h('div',{class:'commit-meta'});
|
|
286
|
+
meta.innerHTML=`<span class="avatar"></span><strong>${esc(c.author.name)}</strong> committed ${timeAgo(c.committed_at)}`;
|
|
287
|
+
const sha=h('a',{class:'commit-sha',href:'#',text:c.short_sha,style:'float:right;margin-top:-24px'});
|
|
288
|
+
sha.onclick=e=>{e.preventDefault();S.view='commit';S.sha=c.sha;render()};
|
|
289
|
+
row.append(msg,meta,sha);
|
|
290
|
+
box.appendChild(row);
|
|
291
|
+
});
|
|
292
|
+
wrap.appendChild(box);
|
|
293
|
+
return wrap;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
async function renderCommit(){
|
|
297
|
+
const c=await load(`commits/${S.sha}.json`);
|
|
298
|
+
const wrap=h('div');
|
|
299
|
+
const box=h('div',{class:'Box'});
|
|
300
|
+
const header=h('div',{class:'Box-header',style:'display:block'});
|
|
301
|
+
header.innerHTML=`<div class="commit-msg" style="font-size:18px;margin-bottom:8px">${esc(c.message_headline)}</div>
|
|
302
|
+
<div class="commit-meta"><span class="avatar"></span><strong>${esc(c.author.name)}</strong> committed ${timeAgo(c.committed_at)}</div>`;
|
|
303
|
+
box.appendChild(header);
|
|
304
|
+
const body=h('div',{style:'padding:16px'});
|
|
305
|
+
if(c.message.split('\n').length>1)body.innerHTML=`<pre style="background:var(--color-canvas-inset);padding:16px;border-radius:6px;white-space:pre-wrap;font-size:13px">${esc(c.message)}</pre>`;
|
|
306
|
+
body.innerHTML+=`<div class="diff-stat" style="margin-top:16px"><span class="add">+${c.stats.additions}</span><span class="del">-${c.stats.deletions}</span><span>${c.stats.changed} files changed</span></div>`;
|
|
307
|
+
box.appendChild(body);
|
|
308
|
+
wrap.appendChild(box);
|
|
309
|
+
if(c.files?.length){
|
|
310
|
+
const files=h('div',{class:'Box',style:'margin-top:16px'});
|
|
311
|
+
files.appendChild(h('div',{class:'Box-header',text:'Files changed'}));
|
|
312
|
+
c.files.forEach(f=>{
|
|
313
|
+
const row=h('div',{class:'Box-row'});
|
|
314
|
+
const status=f.status==='added'?'color:var(--color-success-fg)':f.status==='deleted'?'color:var(--color-danger-fg)':'color:var(--color-attention-fg)';
|
|
315
|
+
row.innerHTML=`<span style="width:20px;${status}">${f.status[0].toUpperCase()}</span><span style="flex:1">${esc(f.path)}</span><span class="diff-stat"><span class="add">+${f.additions}</span><span class="del">-${f.deletions}</span></span>`;
|
|
316
|
+
files.appendChild(row);
|
|
317
|
+
});
|
|
318
|
+
wrap.appendChild(files);
|
|
319
|
+
}
|
|
320
|
+
return wrap;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
async function renderBranches(){
|
|
324
|
+
const branches=await load('branches.json');
|
|
325
|
+
const box=h('div',{class:'Box'});
|
|
326
|
+
box.appendChild(h('div',{class:'Box-header',text:`${branches.length} branches`}));
|
|
327
|
+
branches.forEach(b=>{
|
|
328
|
+
const row=h('div',{class:'Box-row'});
|
|
329
|
+
row.innerHTML=`${b.is_head?'<span style="color:gold;margin-right:8px">★</span>':''}<span style="flex:1"><span class="tag">${svg(icons.branch,12)} ${esc(b.name)}</span></span>
|
|
330
|
+
<span style="color:var(--color-fg-muted);margin-right:16px">${timeAgo(b.committed_at)}</span>`;
|
|
331
|
+
const sha=h('a',{class:'commit-sha',href:'#',text:b.sha.slice(0,7)});
|
|
332
|
+
sha.onclick=e=>{e.preventDefault();S.view='commit';S.sha=b.sha;render()};
|
|
333
|
+
row.appendChild(sha);
|
|
334
|
+
box.appendChild(row);
|
|
335
|
+
});
|
|
336
|
+
return box;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
async function renderTags(){
|
|
340
|
+
const tags=await load('tags.json');
|
|
341
|
+
const box=h('div',{class:'Box'});
|
|
342
|
+
box.appendChild(h('div',{class:'Box-header',text:`${tags.length} tags`}));
|
|
343
|
+
if(!tags.length){box.appendChild(h('div',{class:'empty-state',text:'No tags'}));return box}
|
|
344
|
+
tags.forEach(t=>{
|
|
345
|
+
const row=h('div',{class:'Box-row'});
|
|
346
|
+
row.innerHTML=`<span style="flex:1"><span class="tag">${svg(icons.tag,12)} ${esc(t.name)}</span></span>
|
|
347
|
+
<span style="color:var(--color-fg-muted);margin-right:16px">${timeAgo(t.committed_at)}</span>`;
|
|
348
|
+
const sha=h('a',{class:'commit-sha',href:'#',text:t.sha.slice(0,7)});
|
|
349
|
+
sha.onclick=e=>{e.preventDefault();S.view='commit';S.sha=t.sha;render()};
|
|
350
|
+
row.appendChild(sha);
|
|
351
|
+
box.appendChild(row);
|
|
352
|
+
});
|
|
353
|
+
return box;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async function renderCompare(){
|
|
357
|
+
const wrap=h('div');
|
|
358
|
+
const branches=await load('branches.json');
|
|
359
|
+
if(!S.base)S.base=S.repo.default_branch;
|
|
360
|
+
if(!S.compare)S.compare=branches.find(b=>b.name!==S.base)?.name||S.base;
|
|
361
|
+
|
|
362
|
+
const sel=h('div',{class:'compare-selector'});
|
|
363
|
+
sel.appendChild(branchDropdown('base-branch',S.base,name=>{S.base=name;render()}));
|
|
364
|
+
sel.appendChild(h('span',{class:'compare-arrow',text:'←'}));
|
|
365
|
+
sel.appendChild(branchDropdown('compare-branch',S.compare,name=>{S.compare=name;render()}));
|
|
366
|
+
wrap.appendChild(sel);
|
|
367
|
+
|
|
368
|
+
const baseBranch=branches.find(b=>b.name===S.base);
|
|
369
|
+
const compareBranch=branches.find(b=>b.name===S.compare);
|
|
370
|
+
if(!baseBranch||!compareBranch)return wrap;
|
|
371
|
+
|
|
372
|
+
const baseCommit=await load(`commits/${baseBranch.sha}.json`);
|
|
373
|
+
const compareCommit=await load(`commits/${compareBranch.sha}.json`);
|
|
374
|
+
|
|
375
|
+
const info=h('div',{class:'Box',style:'margin-top:16px'});
|
|
376
|
+
info.innerHTML=`<div class="Box-header">Comparing <strong>${esc(S.base)}</strong> with <strong>${esc(S.compare)}</strong></div>
|
|
377
|
+
<div style="padding:16px">
|
|
378
|
+
<p><strong>Base:</strong> ${esc(baseCommit.message_headline)} <a href="#" class="commit-sha base-sha">${baseCommit.short_sha}</a></p>
|
|
379
|
+
<p style="margin-top:8px"><strong>Compare:</strong> ${esc(compareCommit.message_headline)} <a href="#" class="commit-sha compare-sha">${compareCommit.short_sha}</a></p>
|
|
380
|
+
</div>`;
|
|
381
|
+
info.querySelector('.base-sha').onclick=e=>{e.preventDefault();S.view='commit';S.sha=baseBranch.sha;render()};
|
|
382
|
+
info.querySelector('.compare-sha').onclick=e=>{e.preventDefault();S.view='commit';S.sha=compareBranch.sha;render()};
|
|
383
|
+
wrap.appendChild(info);
|
|
384
|
+
|
|
385
|
+
if(compareCommit.files?.length){
|
|
386
|
+
const diff=h('div',{class:'Box compare-diff'});
|
|
387
|
+
diff.appendChild(h('div',{class:'Box-header',html:`<span>Files changed in compare branch</span><span class="diff-stat"><span class="add">+${compareCommit.stats.additions}</span><span class="del">-${compareCommit.stats.deletions}</span></span>`}));
|
|
388
|
+
compareCommit.files.forEach(f=>{
|
|
389
|
+
const row=h('div',{class:'Box-row'});
|
|
390
|
+
const st=f.status==='added'?'var(--color-success-fg)':f.status==='deleted'?'var(--color-danger-fg)':'var(--color-attention-fg)';
|
|
391
|
+
row.innerHTML=`<span style="width:20px;color:${st}">${f.status[0].toUpperCase()}</span><span style="flex:1">${esc(f.path)}</span><span class="diff-stat"><span class="add">+${f.additions}</span><span class="del">-${f.deletions}</span></span>`;
|
|
392
|
+
diff.appendChild(row);
|
|
393
|
+
});
|
|
394
|
+
wrap.appendChild(diff);
|
|
395
|
+
}
|
|
396
|
+
return wrap;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
async function render(){
|
|
400
|
+
hideError();renderNav();
|
|
401
|
+
const app=$('app');
|
|
402
|
+
app.innerHTML='<div class="loading">Loading...</div>';
|
|
403
|
+
try{
|
|
404
|
+
let view;
|
|
405
|
+
switch(S.view){
|
|
406
|
+
case'code':view=await renderCode();break;
|
|
407
|
+
case'commits':view=await renderCommits();break;
|
|
408
|
+
case'commit':view=await renderCommit();break;
|
|
409
|
+
case'branches':view=await renderBranches();break;
|
|
410
|
+
case'tags':view=await renderTags();break;
|
|
411
|
+
case'compare':view=await renderCompare();break;
|
|
412
|
+
}
|
|
413
|
+
app.innerHTML='';app.appendChild(view);
|
|
414
|
+
}catch(e){showError(e.message);app.innerHTML=''}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
async function init(){
|
|
418
|
+
try{
|
|
419
|
+
S.repo=await load('repo.json');
|
|
420
|
+
S.ref=S.repo.default_branch;
|
|
421
|
+
$('repo-name').textContent=S.repo.name;
|
|
422
|
+
document.title=S.repo.name+' - Git Browser';
|
|
423
|
+
render();
|
|
424
|
+
}catch(e){showError('Failed to load. Run the Ruby script first and serve with: python3 -m http.server')}
|
|
425
|
+
}
|
|
426
|
+
init();
|
|
427
|
+
</script>
|
|
428
|
+
</body>
|
|
429
|
+
</html>
|
data/lib/gitem.rb
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'rugged'
|
|
6
|
+
require 'time'
|
|
7
|
+
|
|
8
|
+
require_relative "gitem/version"
|
|
9
|
+
|
|
10
|
+
module Gitem
|
|
11
|
+
class Error < StandardError; end
|
|
12
|
+
|
|
13
|
+
class GitToJson
|
|
14
|
+
def initialize(repo_path, output_dir = nil)
|
|
15
|
+
@repo = Rugged::Repository.new(repo_path)
|
|
16
|
+
@output_dir = output_dir || File.join(@repo.path, 'srv')
|
|
17
|
+
@processed_trees = Set.new
|
|
18
|
+
@processed_blobs = Set.new
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def export!
|
|
22
|
+
setup_directories
|
|
23
|
+
export_branches
|
|
24
|
+
export_tags
|
|
25
|
+
export_commits
|
|
26
|
+
export_repo_info
|
|
27
|
+
puts "\n✓ Export complete! Files written to #{@output_dir}"
|
|
28
|
+
puts " Serve with: cd #{@output_dir} && ruby -run -e httpd . 8000"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def setup_directories
|
|
34
|
+
%w[commits trees blobs refs/heads refs/tags].each do |dir|
|
|
35
|
+
FileUtils.mkdir_p(File.join(@output_dir, dir))
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def export_repo_info
|
|
40
|
+
default_branch = default_branch_name
|
|
41
|
+
branch = @repo.branches[default_branch]
|
|
42
|
+
readme_content = nil
|
|
43
|
+
readme_name = nil
|
|
44
|
+
|
|
45
|
+
if branch&.target
|
|
46
|
+
tree = branch.target.tree
|
|
47
|
+
%w[README.md README.markdown readme.md README.txt README].each do |name|
|
|
48
|
+
entry = tree.each.find { |e| e[:name].downcase == name.downcase }
|
|
49
|
+
if entry && entry[:type] == :blob
|
|
50
|
+
blob = @repo.lookup(entry[:oid])
|
|
51
|
+
readme_content = blob.content.encode('UTF-8', invalid: :replace, undef: :replace) unless blob.binary?
|
|
52
|
+
readme_name = entry[:name]
|
|
53
|
+
break
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
info = {
|
|
59
|
+
name: File.basename(@repo.workdir || @repo.path.chomp('/.git/').chomp('.git')),
|
|
60
|
+
default_branch: default_branch,
|
|
61
|
+
branches_count: @repo.branches.count { |b| b.name && !b.name.include?('/') },
|
|
62
|
+
tags_count: @repo.tags.count,
|
|
63
|
+
readme: readme_content,
|
|
64
|
+
readme_name: readme_name,
|
|
65
|
+
generated_at: Time.now.iso8601
|
|
66
|
+
}
|
|
67
|
+
write_json('repo.json', info)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def default_branch_name
|
|
71
|
+
%w[main master].find { |name| @repo.branches[name] } || @repo.branches.first&.name || 'main'
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def export_branches
|
|
75
|
+
branches = @repo.branches.map do |branch|
|
|
76
|
+
next if branch.name.nil? || branch.name.include?('/')
|
|
77
|
+
target = branch.target rescue nil
|
|
78
|
+
next unless target
|
|
79
|
+
{
|
|
80
|
+
name: branch.name,
|
|
81
|
+
sha: target.oid,
|
|
82
|
+
is_head: branch.head?,
|
|
83
|
+
committed_at: target.committer[:time].iso8601,
|
|
84
|
+
author: target.author[:name],
|
|
85
|
+
message: target.message.lines.first&.strip || ''
|
|
86
|
+
}
|
|
87
|
+
end.compact.sort_by { |b| b[:is_head] ? 0 : 1 }
|
|
88
|
+
|
|
89
|
+
write_json('branches.json', branches)
|
|
90
|
+
branches.each { |b| write_json("refs/heads/#{b[:name]}.json", b) }
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def export_tags
|
|
94
|
+
tags = @repo.tags.map do |tag|
|
|
95
|
+
target = tag.target rescue nil
|
|
96
|
+
next unless target
|
|
97
|
+
commit = target.is_a?(Rugged::Tag::Annotation) ? target.target : target
|
|
98
|
+
{
|
|
99
|
+
name: tag.name,
|
|
100
|
+
sha: commit.oid,
|
|
101
|
+
annotated: target.is_a?(Rugged::Tag::Annotation),
|
|
102
|
+
message: target.is_a?(Rugged::Tag::Annotation) ? target.message : nil,
|
|
103
|
+
committed_at: commit.committer[:time].iso8601
|
|
104
|
+
}
|
|
105
|
+
end.compact.sort_by { |t| t[:committed_at] }.reverse
|
|
106
|
+
|
|
107
|
+
write_json('tags.json', tags)
|
|
108
|
+
tags.each { |t| write_json("refs/tags/#{t[:name]}.json", t) }
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def export_commits
|
|
112
|
+
commits_list = []
|
|
113
|
+
walker = Rugged::Walker.new(@repo)
|
|
114
|
+
|
|
115
|
+
@repo.branches.each do |branch|
|
|
116
|
+
next if branch.target.nil?
|
|
117
|
+
walker.push(branch.target.oid) rescue nil
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_DATE)
|
|
121
|
+
|
|
122
|
+
walker.each_with_index do |commit, idx|
|
|
123
|
+
print "\rProcessing commit #{idx + 1}..." if (idx + 1) % 10 == 0
|
|
124
|
+
|
|
125
|
+
commit_data = extract_commit(commit)
|
|
126
|
+
commits_list << commit_data.slice(:sha, :short_sha, :message_headline, :author, :committed_at)
|
|
127
|
+
|
|
128
|
+
write_json("commits/#{commit.oid}.json", commit_data)
|
|
129
|
+
export_tree(commit.tree, '')
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
commits_list.sort_by! { |c| c[:committed_at] }.reverse!
|
|
133
|
+
write_json('commits.json', commits_list)
|
|
134
|
+
puts "\rProcessed #{commits_list.size} commits"
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def extract_commit(commit)
|
|
138
|
+
parents = commit.parents.map { |p| { sha: p.oid, short_sha: p.oid[0..6] } }
|
|
139
|
+
diff_stats = commit.parents.empty? ? initial_diff_stats(commit) : parent_diff_stats(commit)
|
|
140
|
+
|
|
141
|
+
{
|
|
142
|
+
sha: commit.oid,
|
|
143
|
+
short_sha: commit.oid[0..6],
|
|
144
|
+
message: commit.message,
|
|
145
|
+
message_headline: commit.message.lines.first&.strip || '',
|
|
146
|
+
author: { name: commit.author[:name], email: commit.author[:email], date: commit.author[:time].iso8601 },
|
|
147
|
+
committer: { name: commit.committer[:name], email: commit.committer[:email], date: commit.committer[:time].iso8601 },
|
|
148
|
+
committed_at: commit.committer[:time].iso8601,
|
|
149
|
+
parents: parents,
|
|
150
|
+
tree_sha: commit.tree.oid,
|
|
151
|
+
stats: diff_stats[:stats],
|
|
152
|
+
files: diff_stats[:files]
|
|
153
|
+
}
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def initial_diff_stats(commit)
|
|
157
|
+
files = []
|
|
158
|
+
collect_tree_files(commit.tree, '', files)
|
|
159
|
+
{ stats: { additions: files.sum { |f| f[:additions] }, deletions: 0, changed: files.size }, files: files }
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def collect_tree_files(tree, path, files)
|
|
163
|
+
tree.each do |entry|
|
|
164
|
+
full_path = path.empty? ? entry[:name] : "#{path}/#{entry[:name]}"
|
|
165
|
+
if entry[:type] == :blob
|
|
166
|
+
blob = @repo.lookup(entry[:oid])
|
|
167
|
+
lines = blob.binary? ? 0 : blob.content.lines.count
|
|
168
|
+
files << { path: full_path, additions: lines, deletions: 0, status: 'added' }
|
|
169
|
+
elsif entry[:type] == :tree
|
|
170
|
+
collect_tree_files(@repo.lookup(entry[:oid]), full_path, files)
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def parent_diff_stats(commit)
|
|
176
|
+
diff = commit.parents.first.diff(commit)
|
|
177
|
+
files = []
|
|
178
|
+
additions = deletions = 0
|
|
179
|
+
|
|
180
|
+
diff.each_patch do |patch|
|
|
181
|
+
file_adds = file_dels = 0
|
|
182
|
+
patch.each_hunk { |h| h.each_line { |l| l.addition? ? file_adds += 1 : (file_dels += 1 if l.deletion?) } }
|
|
183
|
+
additions += file_adds
|
|
184
|
+
deletions += file_dels
|
|
185
|
+
|
|
186
|
+
status = case patch.delta.status
|
|
187
|
+
when :added then 'added'
|
|
188
|
+
when :deleted then 'deleted'
|
|
189
|
+
when :renamed then 'renamed'
|
|
190
|
+
else 'modified'
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
files << { path: patch.delta.new_file[:path], additions: file_adds, deletions: file_dels, status: status }
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
{ stats: { additions: additions, deletions: deletions, changed: files.size }, files: files }
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def export_tree(tree, path)
|
|
200
|
+
return if @processed_trees.include?(tree.oid)
|
|
201
|
+
@processed_trees.add(tree.oid)
|
|
202
|
+
|
|
203
|
+
entries = tree.map do |entry|
|
|
204
|
+
entry_data = {
|
|
205
|
+
name: entry[:name],
|
|
206
|
+
path: path.empty? ? entry[:name] : "#{path}/#{entry[:name]}",
|
|
207
|
+
type: entry[:type].to_s,
|
|
208
|
+
sha: entry[:oid],
|
|
209
|
+
mode: entry[:filemode].to_s(8)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if entry[:type] == :tree
|
|
213
|
+
export_tree(@repo.lookup(entry[:oid]), entry_data[:path])
|
|
214
|
+
elsif entry[:type] == :blob
|
|
215
|
+
export_blob(entry[:oid], entry_data[:path])
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
entry_data
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
write_json("trees/#{tree.oid}.json", { sha: tree.oid, path: path, entries: entries })
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def export_blob(oid, path)
|
|
225
|
+
return if @processed_blobs.include?(oid)
|
|
226
|
+
@processed_blobs.add(oid)
|
|
227
|
+
|
|
228
|
+
blob = @repo.lookup(oid)
|
|
229
|
+
data = {
|
|
230
|
+
sha: oid,
|
|
231
|
+
path: path,
|
|
232
|
+
size: blob.size,
|
|
233
|
+
binary: blob.binary?,
|
|
234
|
+
content: blob.binary? ? nil : safe_content(blob.content),
|
|
235
|
+
truncated: !blob.binary? && blob.size > 100_000
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
write_json("blobs/#{oid}.json", data)
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
def safe_content(content)
|
|
242
|
+
return content[0..100_000] + "\n... [truncated]" if content.size > 100_000
|
|
243
|
+
content.encode('UTF-8', invalid: :replace, undef: :replace, replace: '�')
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
def write_json(path, data)
|
|
247
|
+
File.write(File.join(@output_dir, path), JSON.pretty_generate(data))
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
end
|
data/sig/gitem.rbs
ADDED
metadata
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: gitem
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- mo khan
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: fileutils
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: json
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '2.0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '2.0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: open3
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0.1'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0.1'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: rugged
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '1.0'
|
|
61
|
+
type: :runtime
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '1.0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: time
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0.1'
|
|
75
|
+
type: :runtime
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0.1'
|
|
82
|
+
description: A static site generated for git repositories.
|
|
83
|
+
email:
|
|
84
|
+
- mo@mokhan.ca
|
|
85
|
+
executables:
|
|
86
|
+
- gitem
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- LICENSE.txt
|
|
91
|
+
- README.md
|
|
92
|
+
- Rakefile
|
|
93
|
+
- exe/gitem
|
|
94
|
+
- lib/gitem.rb
|
|
95
|
+
- lib/gitem/index.html.erb
|
|
96
|
+
- lib/gitem/version.rb
|
|
97
|
+
- sig/gitem.rbs
|
|
98
|
+
homepage: https://mokhan.ca/xlgmokha/gitem
|
|
99
|
+
licenses:
|
|
100
|
+
- MIT
|
|
101
|
+
metadata:
|
|
102
|
+
allowed_push_host: https://rubygems.org
|
|
103
|
+
homepage_uri: https://mokhan.ca/xlgmokha/gitem
|
|
104
|
+
source_code_uri: https://mokhan.ca/xlgmokha/gitem
|
|
105
|
+
rdoc_options: []
|
|
106
|
+
require_paths:
|
|
107
|
+
- lib
|
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
|
+
requirements:
|
|
110
|
+
- - ">="
|
|
111
|
+
- !ruby/object:Gem::Version
|
|
112
|
+
version: 3.4.0
|
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
requirements: []
|
|
119
|
+
rubygems_version: 4.0.1
|
|
120
|
+
specification_version: 4
|
|
121
|
+
summary: A static site generated for git repositories.
|
|
122
|
+
test_files: []
|