tworingtools 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/changetag +123 -0
  3. data/bin/sync-forks +7 -3
  4. metadata +5 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03e283802686ddec482dfa738d63a288146317b151a23ac375f4e29dcfa68e5b
4
- data.tar.gz: 4944611322f47b1435b638b7c39d0809f869b1d73cf718f9b9e7f92203b3baf8
3
+ metadata.gz: 92b3d2b2119f4550caa1bea34457c623f70f406947393765b46f60b7e55cb9ae
4
+ data.tar.gz: 6abbde855a4bb79818e6833b464724583cef15acfe1b80180953697dad420d99
5
5
  SHA512:
6
- metadata.gz: da70cf856c13914d7d220f9bacf3829548dc2db82e4a6f464e243f8f8bbfcdca5d67fe33d3ad0ca9d28b859f88d8a4319bcfb0f6fc178c54c6d897888ade15d8
7
- data.tar.gz: e2d273bcd615287e2fef46e172b91c403fb38e8ccca57ed9deedb66a19d5d6c2b4dcdb6e4df4b8a844b932e63c2111fb2e225d4bf18fb929e6f0cd4e9f164f20
6
+ metadata.gz: 8044bfc8f56b663876098c1b696f203112494917fde9c42ded6d2f9578f636d2bbb8f478c9f5683407659edf7fd30c27121a93162edf68d4ab48cb06e0b27dcf
7
+ data.tar.gz: b957e3e536cf096da7c1bd0ce70a0f48076c3491baaaa98a2322dbd99280254010fe811e17e482ebb3343967d9cd3d8b7162ccd8806ba76fb501e2f618bbe0f8
@@ -0,0 +1,123 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require_relative '../lib/echoexec'
5
+
6
+ # failure modes
7
+ ILLEGAL_COMMENT_CHAR = 65
8
+ INVALID_CHANGELOG_PATH = 66
9
+ UNFORCED_ANNOTATION_OVERWRITE_ATTEMPT = 67
10
+ CHANGELOG_ENTRY_NOT_FOUND = 68
11
+
12
+ options = {}
13
+ parser = OptionParser.new do |opts|
14
+ opts.banner = <<~BANNER
15
+
16
+ Usage: changetag [options] <changelog-path> <tag-name>
17
+
18
+ Write changes from changelogs into git tags.
19
+
20
+ For normal usage, provide the path to the changelog from which to extract release notes, and the git tag name for which you'd like to extract release notes. This pulls the relevant section from your changelog, as long as you adhere to the format described at http://keepachangelog.com/en/1.0.0/.
21
+
22
+ Note that the specification requires using the '#' character for hierarchical organization. Conveniently, this also renders different header styles with markdown. Unfortunately, that character is used to denote comments in git tag annotations (similar to git commit messages). So, before using changetag, you must change this to a different character:
23
+
24
+ $> git config core.commentchar "@"
25
+
26
+ changetag looks for this configuration setting, and if it's set to ‘#’, will fail with a message instructing you to change it.
27
+
28
+ By default, changetag tries to extract the relevant section from your changelog using the name of the git tag you supply. If your changelog entries differ from your tag names, you can supply an override using the -n/--name option.
29
+
30
+ Examples:
31
+
32
+ Take the changelog entry for version 1.2.4 and write it into the tag annotation for tag ‘1.2.4’, creating the tag if it doesn't already exist, and overwriting it if it does:
33
+
34
+ $> changetag /path/to/.../CHANGELOG.md 1.2.4
35
+
36
+ Options:
37
+
38
+ BANNER
39
+ opts.on('-f', '--force', 'If a git tag already exists with a nonempty annotation message, overwrite the message. (If this is not supplied, changetag will quit with a warning that you are attempting to overwrite an existing tag annotation.)') do |force| options[:force] = true end
40
+ opts.on('-nNAME', '--name=NAME', 'By default, changetag tries to extract the relevant section from your changelog using the name of the git tag you supply. If your changelog entries differ from your tag names, you can supply an override using this option. Make sure that it includes all content contained withing the square brackes for the entry header.') do |name| options[:name] = name end
41
+ end
42
+ parser.parse!
43
+
44
+ # check for a valid git message comment character
45
+
46
+ comment_char = `git config --get core.commentchar`.strip
47
+ if comment_char == '' or comment_char == '#' then
48
+ puts 'Your git comment character is still set to ‘#’. You need to change it to another character before using changetag. For instance:'
49
+ puts
50
+ puts "\tgit config core.commentchar '@'"
51
+ puts
52
+ exit ILLEGAL_COMMENT_CHAR
53
+ end
54
+
55
+ # get the changelog entry contents
56
+
57
+ changelog_path = ARGV[0]
58
+
59
+ unless File.file?(changelog_path) then
60
+ puts "The path '#{changelog_path}' does not point to a valid file."
61
+ exit INVALID_CHANGELOG_PATH
62
+ end
63
+
64
+ git_tag = ARGV[1]
65
+ current_git_tag_annotation = `git tag -n #{git_tag}`.strip
66
+ git_tag_exists = current_git_tag_annotation != ''
67
+ if git_tag_exists and current_git_tag_annotation != git_tag and options[:force] != true then
68
+ puts "The tag #{git_tag} already has an annotation. To overwrite it, call changetag with the -f/--force option."
69
+ exit UNFORCED_ANNOTATION_OVERWRITE_ATTEMPT
70
+ end
71
+
72
+ =begin
73
+ Extract the relevant section from the changelog, which should have the following format: (square brackets should be present, chevrons are to denote content descriptions)
74
+
75
+ ## [<entry-name>] <entry-date>
76
+
77
+ <contents>
78
+
79
+ ## [<subsequent-entry-name>] <entry-date>
80
+
81
+ <contents>
82
+
83
+ ... etc ...
84
+ =end
85
+ changelog_contents = File.open(changelog_path).readlines
86
+ if options[:name] != nil then
87
+ entry_name = options[:name]
88
+ else
89
+ entry_name = git_tag
90
+ end
91
+
92
+ entry_start_idx = -1
93
+ changelog_contents.each_with_index do |line, i|
94
+ next if line[0..2] != '## '
95
+ if line.include?("[#{entry_name}]") then
96
+ entry_start_idx = i
97
+ break
98
+ end
99
+ end
100
+
101
+ if entry_start_idx == -1 then
102
+ puts "Could not find an entry in the changelog named '#{entry_name}'."
103
+ exit CHANGELOG_ENTRY_NOT_FOUND
104
+ end
105
+
106
+ entry_end_idx = -1
107
+ changelog_contents.each_with_index do |line, i|
108
+ next if i <= entry_start_idx
109
+ if line[0..2] == '## ' then
110
+ entry_end_idx = i - 1
111
+ break
112
+ end
113
+ end
114
+
115
+ entry_contents = changelog_contents[entry_start_idx..entry_end_idx].select{|x| x != "\n"}.join("\n").gsub('`', '\\\`').gsub("'", '\\\'').gsub('"', '\\\"').split("\n").join("\n")
116
+
117
+ # create or edit a git tag with the changelog contents
118
+
119
+ if git_tag_exists then
120
+ echo_and_exec "git tag #{git_tag} #{git_tag} -f -m \"#{entry_contents}\""
121
+ else
122
+ echo_and_exec "git tag #{git_tag} -m \"#{entry_contents}\""
123
+ end
@@ -5,6 +5,10 @@ require 'json'
5
5
  require 'optparse'
6
6
  require_relative '../lib/echoexec'
7
7
 
8
+ # failure modes
9
+ FURTHER_REQUESTS_REQUIRE_TOKEN = 65
10
+ MISSING_REQUIRED_CREDENTIALS = 66
11
+
8
12
  options = {}
9
13
  parser = OptionParser.new do |opts|
10
14
  opts.banner = <<~BANNER
@@ -52,11 +56,11 @@ elsif nil != options[:username] && nil != options[:password]
52
56
  puts
53
57
  puts "\tsync-forks -u #{user} -t #{token.token}"
54
58
  puts
55
- exit
59
+ exit FURTHER_REQUESTS_REQUIRE_TOKEN
56
60
  else
57
61
  puts "Must provide either a username/token or username/password/otp combination to authenticate."
58
62
  puts parser
59
- exit
63
+ exit MISSING_REQUIRED_CREDENTIALS
60
64
  end
61
65
 
62
66
  repos = github.repos.list user: options[:username], auto_pagination: true
@@ -80,7 +84,7 @@ forks.each do |forked|
80
84
  else
81
85
  echo_and_exec "git clone #{url}"
82
86
  Dir.chdir "#{name}"
83
- echo_and_exec "git remote add upstream #{fork_url} --mirror=fetch"
87
+ echo_and_exec "git remote add upstream #{fork_url}"
84
88
  Dir.chdir ".."
85
89
  end
86
90
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tworingtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew McKnight
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-24 00:00:00.000000000 Z
11
+ date: 2018-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: github_api
@@ -41,13 +41,16 @@ dependencies:
41
41
  description: |2
42
42
  - rebuild-sims: Delete all simulators and recreate one for each compatible platform and device type pairing.
43
43
  - sync-forks: Make sure all your GitHub forks are clones into a given directory, and have “upstream” remotes pointing to the repos that were forked.
44
+ - changetag: Extract changelog entries to write into git tag annotation messages.
44
45
  email: andrew@tworingsoft.com
45
46
  executables:
46
47
  - rebuild-sims
47
48
  - sync-forks
49
+ - changetag
48
50
  extensions: []
49
51
  extra_rdoc_files: []
50
52
  files:
53
+ - bin/changetag
51
54
  - bin/rebuild-sims
52
55
  - bin/sync-forks
53
56
  - lib/echoexec.rb