This repository has been archived by the owner on Apr 11, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
334 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
pkg | |||
*.gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
Copyright (c) 2009 Alexander Lang | |||
|
|||
Permission is hereby granted, free of charge, to any person obtaining | |||
a copy of this software and associated documentation files (the | |||
"Software"), to deal in the Software without restriction, including | |||
without limitation the rights to use, copy, modify, merge, publish, | |||
distribute, sublicense, and/or sell copies of the Software, and to | |||
permit persons to whom the Software is furnished to do so, subject to | |||
the following conditions: | |||
|
|||
The above copyright notice and this permission notice shall be | |||
included in all copies or substantial portions of the Software. | |||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
require 'rubygems' | |||
require 'rake' | |||
|
|||
begin | |||
require 'jeweler' | |||
Jeweler::Tasks.new do |gem| | |||
gem.name = "git2mite" | |||
gem.summary = %Q{writes your git commit messages to your mite account} | |||
gem.email = "alex@upstre.am" | |||
gem.homepage = "http://github.com/upstream/git2mite" | |||
gem.authors = ["Alexander Lang", 'Thilo Utke', 'Robin Mehner'] | |||
gem.files = FileList["[A-Z]*.*", "lib/**/*"] | |||
gem.add_dependency 'json' | |||
gem.add_dependency 'rest-client' | |||
gem.add_dependency 'builder' | |||
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings | |||
end | |||
|
|||
rescue LoadError | |||
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler" | |||
end | |||
|
|||
require 'spec/rake/spectask' | |||
desc "Run all specs" | |||
Spec::Rake::SpecTask.new(:spec) do |t| | |||
t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""] | |||
t.spec_files = FileList['spec/*_spec.rb'] | |||
end | |||
|
|||
task :default => :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
#!/usr/bin/env ruby | |||
|
|||
require 'git2mite' | |||
Git2Mite::App.new.run |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,58 @@ | |||
module Git2Mite | |||
class App | |||
def configuration | |||
@configuration ||= Git2Mite::Configuration.new | |||
end | |||
|
|||
def get_api_key | |||
configuration.api_key ||= @gui.ask('What is your api key?').strip | |||
end | |||
|
|||
def get_sub_domain | |||
configuration.sub_domain ||= @gui.ask('What is your account subdomain?').strip | |||
end | |||
|
|||
def check_if_git_repo! | |||
@gui.error "Please change to a directory that is a git repository." unless @repo.is_git_repo? | |||
end | |||
|
|||
def check_ruby_version! | |||
@gui.error "Sorry you need Ruby 1.8.7+ for this." if RUBY_VERSION < '1.8.7' | |||
end | |||
|
|||
|
|||
def initialize | |||
@gui = Gui.new | |||
@repo = GitRepo.new | |||
end | |||
|
|||
def run | |||
@gui.print_welcome | |||
check_if_git_repo! | |||
check_ruby_version! | |||
client = MiteClient.new("http://#{get_sub_domain}.mite.yo.lk", get_api_key) | |||
project_id = @gui.get_project_id(client.projects) | |||
user_id = @gui.get_user_id(User.all(client)) | |||
start_date = @gui.get_date('start date') | |||
end_date = @gui.get_date('end date') | |||
commits = @repo.commits start_date, end_date | |||
author = @gui.get_author commits.map{|date, message, _author| _author}.uniq | |||
|
|||
puts | |||
puts 'Writing commits to mite' | |||
|
|||
commits.each do |date, message, _author| | |||
next unless _author == author | |||
entries = client.time_entries project_id, user_id, date | |||
if entries.empty? | |||
STDERR.puts "WARN no time entries for commit #{date.to_s}: #{message}" | |||
else | |||
entry = entries[rand(entries.size)]['time_entry'] | |||
client.add_message_to_entry entry, message | |||
print "." | |||
end | |||
end | |||
puts 'done' | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
require 'yaml' | |||
|
|||
module Git2Mite | |||
class Configuration | |||
def initialize(config_file = nil) | |||
@config_file = config_file || ENV['HOME'] + '/.git2mite.yml' | |||
if File.exist?(@config_file) | |||
@config = load_config | |||
else | |||
@config = {} | |||
end | |||
end | |||
|
|||
def api_key | |||
@config[:api_key] | |||
end | |||
|
|||
def sub_domain | |||
@config[:sub_domain] | |||
end | |||
|
|||
def sub_domain=(value) | |||
@config[:sub_domain] = value.strip | |||
store_config | |||
@config[:sub_domain] | |||
end | |||
|
|||
def api_key=(value) | |||
@config[:api_key] = value.strip | |||
store_config | |||
@config[:api_key] | |||
end | |||
|
|||
private | |||
|
|||
def store_config | |||
File.open(@config_file, 'w') do |f| | |||
f << @config.to_yaml | |||
end | |||
end | |||
|
|||
def load_config | |||
YAML.load(File.read(@config_file)) | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
module Git2Mite | |||
class GitRepo | |||
def is_git_repo? | |||
status = `git status 2>&1` | |||
!status.downcase.include?('not a git repo') | |||
end | |||
|
|||
def commits(start_date, end_date) | |||
lines = [] | |||
IO.popen("git log --pretty=format:%ai\\|%s\\|%ae --no-merges --before=#{end_date + 1} --after=#{start_date}") do |io| | |||
while line = io.gets | |||
date, message, author = line.split('|') | |||
lines.unshift [Date.parse(date), message.strip, author.strip] | |||
end | |||
lines | |||
end | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,64 @@ | |||
module Git2Mite | |||
class Gui | |||
def print_welcome | |||
puts <<-WELCOME | |||
Welcome to git2mite | |||
This tool allows to you to write the commit log of | |||
your git repository to your mite account in order | |||
to auto-fill your timesheets. | |||
Brought to you by http://upstream-berlin.com | |||
Question, Problems, Source Code: http://github.com/upstream/git2mite | |||
WELCOME | |||
end | |||
|
|||
def ask(question) | |||
print "#{question}: " | |||
$stdin.gets | |||
end | |||
|
|||
def error(reason) | |||
STDERR.puts reason | |||
exit(-1) | |||
end | |||
|
|||
def get_project_id(projects) | |||
puts "=== Projects ===" | |||
projects.each.with_index do |project, i| | |||
puts "#{i+1}\t#{project['project']['name']}" | |||
end | |||
choice = ask('Which project do you want to write your commits to?') | |||
(projects[choice.to_i - 1] || error('invalid project id'))['project']['id'] | |||
end | |||
|
|||
def get_user_id(users) | |||
puts "\n=== Users ===" | |||
users.each.with_index do |user, i| | |||
puts "#{i+1}\t#{user.name}" | |||
end | |||
choice = ask('Which user do you want to write your commits to?') | |||
(users[choice.to_i - 1] || error('invalid user id')).id | |||
end | |||
|
|||
def get_author(authors) | |||
puts "\n=== Git Authors ===" | |||
authors.each.with_index do |name, i| | |||
puts "#{i+1}\t#{name}" | |||
end | |||
choice = ask('Which author\'s commits to you want to use?') | |||
authors[choice.to_i - 1] || error('Invalid author') | |||
end | |||
|
|||
def get_date(label) | |||
answer = ask("Enter the #{label} (yyyy-mm-dd) [#{Date.today}]") | |||
begin | |||
answer.strip.empty? ? Date.today : Date.parse(answer) | |||
rescue(ArgumentError) | |||
error('invalid date') | |||
end | |||
end | |||
|
|||
end | |||
end |
Oops, something went wrong.