precis 1.0.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.
Files changed (2) hide show
  1. data/bin/precis +75 -0
  2. metadata +47 -0
data/bin/precis ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # precis
4
+ #
5
+ # Watches Git repositories, and emails you a weekly (or daily, or
6
+ # monthly, whichever you choose) summary of the activity on them.
7
+ #
8
+ # Author: Rob Miller <rob@bigfish.co.uk>
9
+
10
+ require 'date'
11
+
12
+ output = ""
13
+
14
+ # A quick 'n' dirty function for indenting a string; we use it for the
15
+ # git shortlog output.
16
+ class String
17
+ def indent(char, level = nil)
18
+ level ||= 1
19
+ "#{char * level}" + self.gsub(/\n/, "\n#{char * level}")
20
+ end
21
+ end
22
+
23
+ period = ARGV.shift
24
+ unless ["daily", "weekly", "monthly"].include? period
25
+ period = "weekly"
26
+ end
27
+
28
+ # Git expects a "since" date, so we need to map our periods to a date
29
+ now = Date.today
30
+
31
+ case period
32
+ when "daily"
33
+ since = now - 1
34
+ when "weekly"
35
+ since = now - 7
36
+ when "monthly"
37
+ # It's debatable whether we should do "in the current calendar
38
+ # month" (in which case this can only really be run on the last day
39
+ # of the month), or whether it should be "in the last, say, 31
40
+ # days", in which case it will slowly get out of sync with calendar
41
+ # months.
42
+ since = now.strftime("%Y-%m-01")
43
+ end
44
+
45
+ since = since.strftime("%Y-%m-%d")
46
+
47
+ output += "Oh joy! It's the #{period} Git update.\n"
48
+ output += "These are the stats since #{since}.\n\n"
49
+
50
+ repos = []
51
+
52
+ ARGV.each do |path|
53
+ if File.exists?(path) and File.exists?(path + "/.git")
54
+ repos << File.expand_path(path)
55
+ end
56
+ end
57
+
58
+ repos.each do |repo|
59
+ Dir.chdir(repo)
60
+
61
+ total_commits = `git log --oneline --since="#{since}" | wc -l`.strip
62
+
63
+ if total_commits == "0"
64
+ output += "There were 0 commits in #{File.basename(repo)}.\n"
65
+ else
66
+ total_commits = total_commits == "1" ? "was #{total_commits} commit" : "were #{total_commits} commits"
67
+
68
+ output += "There #{total_commits} in #{File.basename(repo)}:\n\n"
69
+ output += `git shortlog -ne --since="#{since}"`.strip.indent("\t")
70
+
71
+ output += "\n\n"
72
+ end
73
+ end
74
+
75
+ puts output
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: precis
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rob Miller
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-20 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Watches the Git repositories you tell it to, and then emails you a weekly
15
+ summary of activity.
16
+ email: rob@bigfish.co.uk
17
+ executables:
18
+ - precis
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - bin/precis
23
+ homepage: https://github.com/robmiller/precis
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.25
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: Summarises Git activity
47
+ test_files: []