tagurit 0.2

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 (4) hide show
  1. data/bin/tagurit +71 -0
  2. data/lib/tag_fetcher.rb +71 -0
  3. data/lib/url_parser.rb +26 -0
  4. metadata +48 -0
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "set"
4
+ require "yaml"
5
+
6
+ require "url_parser"
7
+ require "tag_fetcher"
8
+
9
+ # files used:
10
+ # ~/.tagurit
11
+ # ~/.tagurit/cache - serialized ruby object to represent a cache of previous tags
12
+ # ~/.tagurit/urls - list of repository urls to watch for new tags
13
+ base_dir = File.join Dir.home, ".tagurit"
14
+ urls_path = File.join base_dir, "urls"
15
+ cache_path = File.join base_dir, "cache"
16
+
17
+ # if ~/.tagurit does not exist create it, for convenience
18
+ Dir.mkdir base_dir unless File.directory? base_dir
19
+
20
+ # read the urls
21
+ begin
22
+ vcs_urls = URLParser.parse(File.open(urls_path).read)
23
+ rescue Errno::ENOENT
24
+ puts "you must create %s" % urls_path
25
+ puts "each line must be a url"
26
+ puts "lines beginning with '#' will be counted as comments"
27
+ exit false
28
+ end
29
+
30
+ # cache is in the format {'<url>': '<list of tags>'}
31
+ begin
32
+ old_cache = YAML.load_file cache_path
33
+ rescue Errno::ENOENT
34
+ old_cache = {}
35
+ end
36
+
37
+ # create a new cache
38
+ new_cache = {}
39
+ vcs_urls.each do |vcs_type, urls|
40
+ if vcs_type == :git
41
+ new_cache.merge!(TagFetcher.git(urls))
42
+ elsif vcs_type == :svn
43
+ new_cache.merge!(TagFetcher.svn(urls))
44
+ elsif vcs_type == :hg
45
+ hg_path = File.join base_dir, "hg"
46
+ new_cache.merge!(TagFetcher.hg(urls, hg_path))
47
+ end
48
+ end
49
+
50
+ # compare the new with the old
51
+ new_cache.each do |url, tags|
52
+ # check if the url exists in the old cache
53
+ unless old_cache.has_key? url
54
+ puts "new repo: #{url}"
55
+ next
56
+ end
57
+
58
+ # check if the tag exists in the old cache
59
+ new_tags = Set.new new_cache[url]
60
+ old_tags = Set.new old_cache[url]
61
+
62
+ diff_tags = new_tags - old_tags
63
+
64
+ unless diff_tags.empty?
65
+ puts "new tags for #{url}"
66
+ puts diff_tags.to_a.join("\n")
67
+ end
68
+ end
69
+
70
+ # save the new cache as the old cache
71
+ File.open(cache_path, "w") {|out| YAML.dump new_cache, out}
@@ -0,0 +1,71 @@
1
+ class TagFetcher
2
+ class << self
3
+ # tag fetchers get a list of urls
4
+ # return a dictionary with {"<url>": ["<tags>"]}
5
+ def git urls
6
+ new_cache = {}
7
+
8
+ urls.each do |url|
9
+ raw_tags = `git ls-remote --tags #{url}`
10
+
11
+ # cleanup tags by removing extra data before the tag name
12
+ processed_tags = raw_tags.split("\n").map {|raw_tag| raw_tag.split("/")[-1]}
13
+
14
+ # cleanup tags which end with ^{}
15
+ processed_tags.reject! {|tag| tag[-3, 3] == "^{}"}
16
+
17
+ new_cache[url] = processed_tags
18
+ end
19
+
20
+ new_cache
21
+ end
22
+
23
+ def svn urls
24
+ new_cache = {}
25
+
26
+ urls.each do |url|
27
+ raw_tags = `svn ls #{url}`
28
+
29
+ # only remove the following "/" from the tag directory
30
+ processed_tags = raw_tags.split("\n").map {|raw_tag| raw_tag.split("/")[0]}
31
+
32
+ new_cache[url] = processed_tags
33
+ end
34
+
35
+ new_cache
36
+ end
37
+
38
+ def hg urls, hg_path
39
+ new_cache = {}
40
+
41
+ # create a ~/.tagurit/hg/ directory to hold mercurial repositories.
42
+ # You can only fetch tags from a repository if they are local
43
+ Dir.mkdir hg_path unless File.directory? hg_path
44
+
45
+ urls.each do |url|
46
+ # remove whitespace before and after the string to clean it up
47
+ url.strip!
48
+
49
+ # extract the directory it will fetch into
50
+ local_directory = url.split("/")[-1]
51
+ local_path = File.join hg_path, local_directory
52
+
53
+ # if the directory doesn't exist, clone it first, otherwise pull upstream changes
54
+ if File.directory? local_path
55
+ `hg pull -u -R #{local_path} 2> /dev/null`
56
+ else
57
+ `hg clone #{url} #{local_path} 2> /dev/null`
58
+ end
59
+
60
+ raw_tags = `hg tags -R #{local_path}`
61
+
62
+ # only remove the following "/" from the tag directory
63
+ processed_tags = raw_tags.split("\n").map {|raw_tag| raw_tag.split[0]}
64
+
65
+ new_cache[url] = processed_tags
66
+ end
67
+
68
+ new_cache
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,26 @@
1
+ class URLParser
2
+ def URLParser.parse content
3
+ urls = {git: [], svn: [], hg: []}
4
+ repo_state = :git
5
+
6
+ content.split("\n").each do |line|
7
+ # change the repo state
8
+ # all urls following this will be labeled with this state
9
+ if line.match /^#~(git|svn|hg)/
10
+ repo_state = $1.to_sym
11
+ next
12
+ end
13
+
14
+ # skip comments
15
+ next if line.match /^#/
16
+
17
+ # skip empty lines
18
+ next if line.match /^\s*$/
19
+
20
+ # everything else is considered a url
21
+ urls[repo_state] << line.chomp
22
+ end
23
+
24
+ urls
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tagurit
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Dziedzic
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-01 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Watches multiple types of VCS repositories for new tags.
15
+ email: gostrc@gmail.com
16
+ executables:
17
+ - tagurit
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/url_parser.rb
22
+ - lib/tag_fetcher.rb
23
+ - bin/tagurit
24
+ homepage: https://github.com/gostrc/tagurit
25
+ licenses: []
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.13
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: Version control system, tag watcher.
48
+ test_files: []