trk 0.1.7 → 0.1.9

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -2
  3. data/lib/trk/cli.rb +60 -15
  4. data/lib/trk/version.rb +1 -1
  5. metadata +3 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aadec329696267ada6db94f0d871454eece18090a4566e3a6f9684c406e48db6
4
- data.tar.gz: c2a28757d21a24d0197332ca50c30aa36bf2a69de43accd5e54c550ca8b3b695
3
+ metadata.gz: 90564bb5743c70ff927900dbcb29c94264daa6a9d956f9d5c8459856a248b206
4
+ data.tar.gz: 794412abfb305ca51b57ece396051cfe892677dad151a3ca097aaae5957b1d61
5
5
  SHA512:
6
- metadata.gz: 6d0ed0b289b76acbf65269be76b22a5ad8ea2284e38dbe0a04b48e221a7b17343b80b4df496a2b0dfe3f24e2f8971a0fcedee50490fe7d94c3916db88316edaf
7
- data.tar.gz: 9cde2261c3bad6236099fce1901cb0d5e63965073f3557f1400f7dec939f33922d28399643c14b5e36ecf14d88ab58dca2c74139667ae9c3bca6cc38cbfd6f0e
6
+ metadata.gz: 66fae02f19163eabbe3d992d5c48d9046def0c2538f7d443295e4ca7b14de80542d90310913b99261616e6f18b71161f56b44a415e5923d22446589a8557337e
7
+ data.tar.gz: b9024873d8ad9e7f92d50bb131c0fef22f232cae2d241941ae6cee6e9a9615b985539ee8cb31cd92db4c172aa22854e48f0e4e7ec090c4d2f7c12038785ae34a
data/README.md CHANGED
@@ -42,10 +42,14 @@ Using this gem you can get the string with
42
42
  trk link-show
43
43
  ```
44
44
 
45
+ ### Vim mapping link show
46
+
45
47
  For vim you can use mapping
46
48
  ```
47
49
  # .vimrc
50
+ # Start of code from: https://trk.tools/app/trk-readme-source-links/-/blob/main/README.md
48
51
  nnoremap <leader>s :r !trk link-show %<CR>
52
+ # End of code from: https://trk.tools/app/trk-readme-source-links/-/blob/main/README.md
49
53
 
50
54
  # local gem
51
55
  nnoremap <leader>s :r !cd ~/trk.tools/app/trk-readme-source-links && bundle exec exe/trk link-show %:p<CR>
@@ -83,6 +87,8 @@ trk pull
83
87
 
84
88
  ## Development
85
89
 
90
+ To install this gem onto your local machine, run `bundle exec rake install`.
91
+
86
92
  Run without installing the gem
87
93
  ```
88
94
  bundle exec exe/trk pull
@@ -113,8 +119,13 @@ ruby -Itest test/test_link.rb --name test_link_show_success
113
119
 
114
120
  ## Gem push
115
121
 
116
- To install this gem onto your local machine, run `bundle exec rake install`.
117
- To release a new version, update the version number in `lib/trk/version.rb`, and
122
+ To release a new version, update the version number, git commit
123
+ ```
124
+ vi lib/trk/version.rb
125
+ bundle
126
+
127
+ git commit -am"Update"
128
+ ```
118
129
  then deploy with:
119
130
  ```
120
131
  bundle exec rake release
data/lib/trk/cli.rb CHANGED
@@ -3,6 +3,7 @@ require "open3"
3
3
  require "net/http"
4
4
  require "uri"
5
5
  require "debug"
6
+ require "json"
6
7
 
7
8
  module Trk
8
9
  class CLI < Thor
@@ -47,29 +48,68 @@ module Trk
47
48
  next unless File.directory?(File.join(dir, ".git"))
48
49
 
49
50
  Dir.chdir(dir) do
50
- puts "\nšŸ”„ Pulling updates in: #{dir}"
51
- _stdout, stderr, status = Open3.capture3("git pull")
51
+ puts "\nšŸ”„ Check if the last commit is the same in: #{dir}"
52
+ # Get remote latest commit SHA via glab API
53
+ project_path = dir.sub("#{base_dir}/", "")
54
+ encoded_project = URI.encode_www_form_component(project_path)
55
+ stdout_remote, stderr, status_remote = Open3.capture3("glab api projects/#{encoded_project}/repository/commits?per_page=1")
56
+ if status_remote.success?
57
+ remote_commit = JSON.parse(stdout_remote).first["id"]
58
+ stdout_local, _stderr_local, status_local = Open3.capture3("git rev-parse HEAD")
59
+ local_commit = stdout_local.strip if status_local.success?
60
+ if remote_commit == local_commit
52
61
 
53
- if status.success?
54
- _stdout, stderr, status = Open3.capture3("git push")
55
- if status.success?
56
62
  stdout, stderr, _status = Open3.capture3("git status --porcelain")
57
63
  if stdout.empty?
58
- puts "#{CHECK_ICON} Git pull push successful in: #{dir}"
64
+ puts "#{CHECK_ICON} Up-to-date: #{project_path}, skipping pull"
59
65
  else
60
- puts "#{UNCHECK_ICON} Git status --porcelain failed in: #{dir}\n#{stdout}\n#{stderr}"
61
- puts "Opening shell for manual fix. Type 'exit' when done."
62
- system('PS1="trk pull paused on [$(basename $(pwd))]$ " bash --norc')
66
+ puts "#{UNCHECK_ICON} Up-to-date but Git status --porcelain failed in: #{dir}\n#{stdout}\n#{stderr}"
67
+ system "git status"
68
+ system "git diff"
69
+ puts "Do you want to run 'git add . && git commit -amUpdate' and continue (Y/n) ?"
70
+ answer = $stdin.gets.strip.downcase
71
+ if answer == "" || answer == "y"
72
+ success = system "git add . && git commit -amUpdate && git push"
73
+ open_shell unless success
74
+ else
75
+ open_shell
76
+ end
63
77
  end
64
78
  else
65
- puts "#{UNCHECK_ICON} Git push failed in: #{dir}\n#{stderr}"
66
- puts "Opening shell for manual fix. Type 'exit' when done."
67
- system('PS1="trk pull paused on [$(basename $(pwd))]$ " bash --norc')
79
+ puts "\nšŸ”„ Pulling updates in: #{dir}"
80
+ _stdout, stderr, status = Open3.capture3("git pull")
81
+
82
+ if status.success?
83
+ _stdout, stderr, status = Open3.capture3("git push")
84
+ if status.success?
85
+ stdout, stderr, _status = Open3.capture3("git status --porcelain")
86
+ if stdout.empty?
87
+ puts "#{CHECK_ICON} Git pull push successful in: #{dir}"
88
+ else
89
+ puts "#{UNCHECK_ICON} Git status --porcelain failed in: #{dir}\n#{stdout}\n#{stderr}"
90
+ system "git status"
91
+ system "git diff"
92
+ puts "Do you want to run 'git add . && git commit -amUpdate' and continue (Y/n) ?"
93
+ answer = $stdin.gets.strip.downcase
94
+ if answer == "" || answer == "y"
95
+ success = system "git add . && git commit -amUpdate && git push"
96
+ open_shell unless success
97
+ else
98
+ open_shell
99
+ end
100
+ end
101
+ else
102
+ puts "#{UNCHECK_ICON} Git push failed in: #{dir}\n#{stderr}"
103
+ open_shell
104
+ end
105
+ else
106
+ puts "#{UNCHECK_ICON} Git pull failed in: #{dir}\n#{stderr}"
107
+ open_shell
108
+ end
68
109
  end
69
110
  else
70
- puts "#{UNCHECK_ICON} Git pull failed in: #{dir}\n#{stderr}"
71
- puts "Opening shell for manual fix. Type 'exit' when done."
72
- system('PS1="trk pull paused on [$(basename $(pwd))]$ " bash --norc')
111
+ puts "#{UNCHECK_ICON} Glab api failed: #{dir}\n#{stderr}"
112
+ open_shell
73
113
  end
74
114
  end
75
115
  end
@@ -77,6 +117,11 @@ module Trk
77
117
  puts "\n#{CHECK_ICON} All done!"
78
118
  end
79
119
 
120
+ def open_shell
121
+ puts "Opening shell for manual fix. Type 'exit' when done."
122
+ system('PS1="trk pull paused on [$(basename $(pwd))]$ " bash --norc')
123
+ end
124
+
80
125
  desc "link-show FILENAME", "Show start link of the file"
81
126
  def link_show(filename)
82
127
  result = Link.new(filename).show
data/lib/trk/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Trk
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.9"
5
5
  CHECK_ICON = "āœ… "
6
6
  UNCHECK_ICON = "āŒ "
7
7
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dusan Orlovic
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-03-31 00:00:00.000000000 Z
10
+ date: 2025-05-24 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: thor
@@ -51,7 +50,6 @@ licenses:
51
50
  metadata:
52
51
  homepage_uri: https://trk.tools
53
52
  source_code_uri: https://trk.tools/app/trk-readme-source-links
54
- post_install_message:
55
53
  rdoc_options: []
56
54
  require_paths:
57
55
  - lib
@@ -66,8 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
64
  - !ruby/object:Gem::Version
67
65
  version: '0'
68
66
  requirements: []
69
- rubygems_version: 3.5.16
70
- signing_key:
67
+ rubygems_version: 3.6.2
71
68
  specification_version: 4
72
69
  summary: CLI tools to manipulate https://trk.tools README files and projects.
73
70
  test_files: []