git-harvest 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +59 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/harvest +5 -0
- data/harvest.gemspec +32 -0
- data/lib/harvest.rb +42 -0
- data/lib/harvest/credentials_manager.rb +81 -0
- data/lib/harvest/issue_tracker.rb +50 -0
- data/lib/harvest/time_logger.rb +62 -0
- data/lib/harvest/vcs.rb +26 -0
- data/lib/harvest/version.rb +3 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f5f6424b3e19f7f30a349216749f215eeca8064c408d6672129d66a07d324cb7
|
4
|
+
data.tar.gz: 40fb84c6945b2cf35bf3c99b953272807748eed509c73c9cd12e55e65ce34e55
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1405df20095918c40ab58d35b776d4891814ea2561c0ff19c96dd3905339576e55a343e4279bac822f69cc3c8ede0ee2f3f6e80613ae91b47c74e0b1d35178d8
|
7
|
+
data.tar.gz: 5d06b929a692b541d4855643a64f55924aefa3b5a2a8f1dd4e7582bacd0f14fcd762a7fb2ab42b6f7d8c70b76efb5864f744496e0586dabeeb54f6391e8f6d47
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
harvest
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.5.1
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at makeawish880@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
git-harvest (0.1.0)
|
5
|
+
rest-client
|
6
|
+
thor
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
coderay (1.1.2)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
domain_name (0.5.20180417)
|
14
|
+
unf (>= 0.0.5, < 1.0.0)
|
15
|
+
http-cookie (1.0.3)
|
16
|
+
domain_name (~> 0.5)
|
17
|
+
method_source (0.9.2)
|
18
|
+
mime-types (3.2.2)
|
19
|
+
mime-types-data (~> 3.2015)
|
20
|
+
mime-types-data (3.2018.0812)
|
21
|
+
netrc (0.11.0)
|
22
|
+
pry (0.12.2)
|
23
|
+
coderay (~> 1.1.0)
|
24
|
+
method_source (~> 0.9.0)
|
25
|
+
rake (10.5.0)
|
26
|
+
rest-client (2.0.2)
|
27
|
+
http-cookie (>= 1.0.2, < 2.0)
|
28
|
+
mime-types (>= 1.16, < 4.0)
|
29
|
+
netrc (~> 0.8)
|
30
|
+
rspec (3.8.0)
|
31
|
+
rspec-core (~> 3.8.0)
|
32
|
+
rspec-expectations (~> 3.8.0)
|
33
|
+
rspec-mocks (~> 3.8.0)
|
34
|
+
rspec-core (3.8.0)
|
35
|
+
rspec-support (~> 3.8.0)
|
36
|
+
rspec-expectations (3.8.2)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.8.0)
|
39
|
+
rspec-mocks (3.8.0)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.8.0)
|
42
|
+
rspec-support (3.8.0)
|
43
|
+
thor (0.20.3)
|
44
|
+
unf (0.1.4)
|
45
|
+
unf_ext
|
46
|
+
unf_ext (0.0.7.5)
|
47
|
+
|
48
|
+
PLATFORMS
|
49
|
+
ruby
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
bundler
|
53
|
+
git-harvest!
|
54
|
+
pry
|
55
|
+
rake
|
56
|
+
rspec
|
57
|
+
|
58
|
+
BUNDLED WITH
|
59
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Abhinav Mishra
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Harvest
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/harvest`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'harvest'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install harvest
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/harvest. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Harvest project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/harvest/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "harvest"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/harvest
ADDED
data/harvest.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "harvest/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "git-harvest"
|
8
|
+
spec.version = Harvest::VERSION
|
9
|
+
spec.authors = ["Abhinav Mishra"]
|
10
|
+
spec.email = ["makeawish880@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{CLI for Harvest-JIRA Integration}
|
13
|
+
spec.homepage = "https://github.com/abhinavmsra/harvest"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_dependency "thor"
|
26
|
+
spec.add_dependency "rest-client"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler"
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
spec.add_development_dependency "rspec"
|
31
|
+
spec.add_development_dependency "pry"
|
32
|
+
end
|
data/lib/harvest.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'harvest/version'
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
require 'harvest/vcs'
|
6
|
+
require 'harvest/issue_tracker'
|
7
|
+
require 'harvest/credentials_manager'
|
8
|
+
require 'harvest/time_logger'
|
9
|
+
|
10
|
+
module Harvest
|
11
|
+
class CLI < Thor
|
12
|
+
desc "Setup the gem", "Stores config variables"
|
13
|
+
def init
|
14
|
+
current_project = Harvest::Vcs.current_project
|
15
|
+
raise 'NO Git repo initialized' if current_project.empty?
|
16
|
+
|
17
|
+
credential_manager = Harvest::CredentialsManager.new(current_project)
|
18
|
+
credential_manager.request
|
19
|
+
credential_manager.save
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Start Harvest Timer", "Start tracking of current branch"
|
23
|
+
def start
|
24
|
+
current_project = Harvest::Vcs.current_project
|
25
|
+
|
26
|
+
config = Harvest::CredentialsManager.new(current_project).read[current_project]
|
27
|
+
|
28
|
+
vcs_instance = Harvest::Vcs.new(config['jira']['project_code'])
|
29
|
+
|
30
|
+
issue_tracker = Harvest::IssueTracker.new(
|
31
|
+
config: config['jira'],
|
32
|
+
task_identifier: vcs_instance.ticket_id
|
33
|
+
)
|
34
|
+
issue_tracker.fetch_issue
|
35
|
+
|
36
|
+
Harvest::TimeLogger.new(config['harvest']).log(
|
37
|
+
task_title: issue_tracker.task_title,
|
38
|
+
task_url: issue_tracker.task_url
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Harvest
|
4
|
+
class CredentialsManager < Thor
|
5
|
+
BASE_PATHNAME = '.harvest'.freeze
|
6
|
+
CONFIG_FILENAME = 'config.json'.freeze
|
7
|
+
|
8
|
+
attr_reader :current_project, :credentials
|
9
|
+
|
10
|
+
no_commands do
|
11
|
+
def initialize(current_project)
|
12
|
+
@current_project = current_project
|
13
|
+
end
|
14
|
+
|
15
|
+
def request
|
16
|
+
say "========== JIRA Integration =============", Thor::Shell::Color::GREEN
|
17
|
+
say 'Fetch or create JIRA API credentials at https://id.atlassian.com/manage/api-tokens', Thor::Shell::Color::GREEN
|
18
|
+
|
19
|
+
project_code = ask "Enter JIRA Project code (eg. MXL): ", Thor::Shell::Color::RED, :bold
|
20
|
+
project_url = ask "Enter JIRA project Base URL (eg. https://sephora-mx.atlassian.net): ", Thor::Shell::Color::RED, :bold
|
21
|
+
email = ask "Enter JIRA email: ", Thor::Shell::Color::RED, :bold
|
22
|
+
access_token = ask "Enter JIRA access token: ", Thor::Shell::Color::RED, :bolds
|
23
|
+
|
24
|
+
say "========== Harvest Integration =============", Thor::Shell::Color::GREEN
|
25
|
+
say 'Fetch or create Harvest API credentials at https://id.getharvest.com/developers', Thor::Shell::Color::GREEN
|
26
|
+
|
27
|
+
account_id = ask "Enter Harvest Account ID: ", Thor::Shell::Color::RED, :bold
|
28
|
+
harvest_access_token = ask "Enter Harvest Access Token: ", Thor::Shell::Color::RED, :bold
|
29
|
+
|
30
|
+
harvest_config = {
|
31
|
+
'access_token' => harvest_access_token,
|
32
|
+
'account_id' => account_id
|
33
|
+
}
|
34
|
+
|
35
|
+
projects = Harvest::TimeLogger.new(harvest_config).projects
|
36
|
+
|
37
|
+
selected_project = ask 'Select Project', limited_to: projects.collect { |x| x[:name] }
|
38
|
+
project_id = projects.select {|x| x[:name] == selected_project }[0][:id]
|
39
|
+
|
40
|
+
@credentials = {
|
41
|
+
jira: {
|
42
|
+
project_code: project_code,
|
43
|
+
project_url: project_url,
|
44
|
+
username: email,
|
45
|
+
access_token: access_token
|
46
|
+
},
|
47
|
+
harvest: {
|
48
|
+
account_id: account_id,
|
49
|
+
project_id: project_id,
|
50
|
+
access_token: harvest_access_token
|
51
|
+
}
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def save
|
56
|
+
dirname = File.join(Dir.home, BASE_PATHNAME)
|
57
|
+
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
|
58
|
+
|
59
|
+
current_credentials = self.read
|
60
|
+
current_credentials[current_project] = credentials
|
61
|
+
|
62
|
+
File.open(credentials_path, 'w+') { |f| f.write(current_credentials.to_json) }
|
63
|
+
end
|
64
|
+
|
65
|
+
def read
|
66
|
+
return {} unless File.file?(credentials_path)
|
67
|
+
|
68
|
+
credentials = File.read(credentials_path)
|
69
|
+
return {} if credentials.nil?
|
70
|
+
|
71
|
+
JSON.parse(credentials)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def credentials_path
|
78
|
+
File.join(Dir.home, BASE_PATHNAME, CONFIG_FILENAME)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module Harvest
|
4
|
+
class IssueTracker
|
5
|
+
attr_reader :config, :task_identifier, :task_details
|
6
|
+
|
7
|
+
def initialize(config: , task_identifier:)
|
8
|
+
@config = config
|
9
|
+
@task_identifier = task_identifier
|
10
|
+
end
|
11
|
+
|
12
|
+
def fetch_issue
|
13
|
+
response = RestClient::Request.new(
|
14
|
+
method: :get,
|
15
|
+
url: rest_api_url,
|
16
|
+
user: config['username'],
|
17
|
+
password: config['access_token'],
|
18
|
+
headers: { accept: :json, content_type: :json }
|
19
|
+
).execute
|
20
|
+
|
21
|
+
@task_details = JSON.parse(response.body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def task_title
|
25
|
+
task_details['fields']['summary']
|
26
|
+
end
|
27
|
+
|
28
|
+
def task_id
|
29
|
+
"#{project_code}-#{task_identifier}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def task_url
|
33
|
+
"#{project_url}/browse/#{task_id}"
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def rest_api_url
|
39
|
+
"#{project_url}/rest/api/latest/issue/#{task_id}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def project_code
|
43
|
+
config['project_code']
|
44
|
+
end
|
45
|
+
|
46
|
+
def project_url
|
47
|
+
config['project_url']
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module Harvest
|
4
|
+
class TimeLogger
|
5
|
+
BASE_URL = 'https://api.harvestapp.com/v2'.freeze
|
6
|
+
DEFAULT_USER_AGENT = 'Oozou Harvest CLI (abhinav@oozou.com)'.freeze
|
7
|
+
WEB_DEVELOPMENT_TASK_ID = 10740736
|
8
|
+
|
9
|
+
attr_reader :config
|
10
|
+
|
11
|
+
def initialize(config)
|
12
|
+
@config = config
|
13
|
+
config['task_id'] ||= WEB_DEVELOPMENT_TASK_ID
|
14
|
+
end
|
15
|
+
|
16
|
+
def projects
|
17
|
+
response = RestClient::Request.execute(
|
18
|
+
method: :get,
|
19
|
+
url: "#{BASE_URL}/users/me/project_assignments",
|
20
|
+
headers: headers
|
21
|
+
)
|
22
|
+
|
23
|
+
JSON.parse(response.body)['project_assignments'].map do |project_assignment|
|
24
|
+
{
|
25
|
+
name: project_assignment['project']['name'],
|
26
|
+
id: project_assignment['project']['id']
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def log(task_title:, task_url: nil)
|
32
|
+
RestClient.post(
|
33
|
+
"#{BASE_URL}/time_entries",
|
34
|
+
time_log_payload(task_title, task_url).to_json,
|
35
|
+
headers
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def headers
|
42
|
+
{
|
43
|
+
"Content-Type" => "application/json",
|
44
|
+
"User-Agent"=> DEFAULT_USER_AGENT,
|
45
|
+
"Authorization" => "Bearer #{config['access_token']}",
|
46
|
+
"Harvest-Account-Id" => config['account_id']
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def time_log_payload(task_title, task_url)
|
51
|
+
{
|
52
|
+
project_id: config['project_id'],
|
53
|
+
task_id: config['task_id'],
|
54
|
+
spent_date: Date.today.strftime('%Y-%m-%d'),
|
55
|
+
notes: task_title,
|
56
|
+
external_reference: {
|
57
|
+
permalink: task_url
|
58
|
+
}
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/harvest/vcs.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Harvest
|
2
|
+
class Vcs
|
3
|
+
attr_reader :current_branch, :project_code
|
4
|
+
|
5
|
+
def self.current_project
|
6
|
+
`git config --local remote.origin.url|sed -n 's#.*/\([^.]*\)\.git#\1#p'`
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(project_code)
|
10
|
+
@project_code = project_code
|
11
|
+
@current_branch = git_command_for_current_branch[0..-2]
|
12
|
+
end
|
13
|
+
|
14
|
+
def ticket_id
|
15
|
+
branch_names = current_branch.gsub(/[^0-9a-z]/i, ' ').split
|
16
|
+
|
17
|
+
branch_names[branch_names.index(project_code)+1]
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def git_command_for_current_branch
|
23
|
+
`git rev-parse --abbrev-ref HEAD`
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-harvest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Abhinav Mishra
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- makeawish880@gmail.com
|
100
|
+
executables:
|
101
|
+
- harvest
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".ruby-gemset"
|
108
|
+
- ".ruby-version"
|
109
|
+
- ".travis.yml"
|
110
|
+
- CODE_OF_CONDUCT.md
|
111
|
+
- Gemfile
|
112
|
+
- Gemfile.lock
|
113
|
+
- LICENSE.txt
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- bin/console
|
117
|
+
- bin/setup
|
118
|
+
- exe/harvest
|
119
|
+
- harvest.gemspec
|
120
|
+
- lib/harvest.rb
|
121
|
+
- lib/harvest/credentials_manager.rb
|
122
|
+
- lib/harvest/issue_tracker.rb
|
123
|
+
- lib/harvest/time_logger.rb
|
124
|
+
- lib/harvest/vcs.rb
|
125
|
+
- lib/harvest/version.rb
|
126
|
+
homepage: https://github.com/abhinavmsra/harvest
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.7.7
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: CLI for Harvest-JIRA Integration
|
150
|
+
test_files: []
|