This repository has been archived by the owner on Apr 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
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
7 changed files
with
134 additions
and
124 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 | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,35 @@ | ||
require 'yaml' | ||
|
||
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 = {} | ||
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 | ||
end | ||
|
||
def api_key | ||
@config[:api_key] | ||
end | ||
def api_key | ||
@config[:api_key] | ||
end | ||
|
||
def api_key=(value) | ||
@config[:api_key] = value | ||
store_config | ||
end | ||
def api_key=(value) | ||
@config[:api_key] = value | ||
store_config | ||
end | ||
|
||
private | ||
private | ||
|
||
def store_config | ||
File.open(@config_file, 'w') do |f| | ||
f << @config.to_yaml | ||
def store_config | ||
File.open(@config_file, 'w') do |f| | ||
f << @config.to_yaml | ||
end | ||
end | ||
end | ||
|
||
def load_config | ||
YAML.load(File.read(@config_file)) | ||
def load_config | ||
YAML.load(File.read(@config_file)) | ||
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
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 | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
class GitRepo | ||
def is_git_repo? | ||
status = `git status 2>&1` | ||
!status.downcase.include?('not a git repo') | ||
end | ||
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] | ||
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] | ||
end | ||
end | ||
lines | ||
end | ||
lines | ||
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 | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,60 @@ | ||
class Gui | ||
def print_welcome | ||
puts <<-WELCOME | ||
Welcome to git2mite | ||
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. | ||
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 | ||
Brought to you by http://upstream-berlin.com | ||
Question, Problems, Source Code: http://github.com/upstream/git2mite | ||
WELCOME | ||
end | ||
WELCOME | ||
end | ||
|
||
def ask(question) | ||
print "#{question}: " | ||
gets | ||
end | ||
def ask(question) | ||
print "#{question}: " | ||
gets | ||
end | ||
|
||
def error(reason) | ||
STDERR.puts reason | ||
exit(-1) | ||
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']}" | ||
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 | ||
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}" | ||
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 | ||
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}" | ||
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 | ||
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.parse(answer) rescue error('invalid date') | ||
end | ||
def get_date(label) | ||
answer = ask("Enter the #{label} (yyyy-mm-dd):") | ||
Date.parse(answer) rescue error('invalid date') | ||
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
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 | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
class User | ||
attr_accessor :name, :id | ||
module Git2Mite | ||
class User | ||
attr_accessor :name, :id | ||
|
||
def initialize(attributes = {}) | ||
self.name = attributes[:name] | ||
self.id = attributes[:id] | ||
end | ||
def initialize(attributes = {}) | ||
self.name = attributes[:name] | ||
self.id = attributes[:id] | ||
end | ||
|
||
def self.all(mite_client) | ||
mite_client.get('/users.json').map do |json| | ||
User.new :name => json['user']['name'], :id => json['user']['id'] | ||
def self.all(mite_client) | ||
mite_client.get('/users.json').map do |json| | ||
User.new :name => json['user']['name'], :id => json['user']['id'] | ||
end | ||
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