Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-02-08 12:12:41 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-02-08 12:12:41 +0300
commit0a34f2dcb562098c481140246f7ac22683b38d76 (patch)
tree9b3efbb8fc6874cf735120644de111387dd24e42 /app
parentfa3a7ef0379ec67706a8923a68dec99082a0face (diff)
parentd56c2a9bc58091f906b8d0001600bad448847d4f (diff)
Merge pull request #8580 from j0k3r/asana
Add Asana service
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/services_controller.rb2
-rw-r--r--app/models/project.rb3
-rw-r--r--app/models/project_services/asana_service.rb116
-rw-r--r--app/views/projects/services/_form.html.haml3
4 files changed, 121 insertions, 3 deletions
diff --git a/app/controllers/projects/services_controller.rb b/app/controllers/projects/services_controller.rb
index 5b35cc90413..b3110eacc18 100644
--- a/app/controllers/projects/services_controller.rb
+++ b/app/controllers/projects/services_controller.rb
@@ -47,7 +47,7 @@ class Projects::ServicesController < Projects::ApplicationController
:room, :recipients, :project_url, :webhook,
:user_key, :device, :priority, :sound, :bamboo_url, :username, :password,
:build_key, :server, :teamcity_url, :build_type,
- :description, :issues_url, :new_issue_url
+ :description, :issues_url, :new_issue_url, :restrict_to_branch
)
end
end
diff --git a/app/models/project.rb b/app/models/project.rb
index a9ead7830ab..5adf13588a3 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -69,6 +69,7 @@ class Project < ActiveRecord::Base
has_one :hipchat_service, dependent: :destroy
has_one :flowdock_service, dependent: :destroy
has_one :assembla_service, dependent: :destroy
+ has_one :asana_service, dependent: :destroy
has_one :gemnasium_service, dependent: :destroy
has_one :slack_service, dependent: :destroy
has_one :buildbox_service, dependent: :destroy
@@ -362,7 +363,7 @@ class Project < ActiveRecord::Base
end
def available_services_names
- %w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla
+ %w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla asana
emails_on_push gemnasium slack pushover buildbox bamboo teamcity jira redmine custom_issue_tracker)
end
diff --git a/app/models/project_services/asana_service.rb b/app/models/project_services/asana_service.rb
new file mode 100644
index 00000000000..db1e7a2b1cb
--- /dev/null
+++ b/app/models/project_services/asana_service.rb
@@ -0,0 +1,116 @@
+# == Schema Information
+#
+# Table name: services
+#
+# id :integer not null, primary key
+# type :string(255)
+# title :string(255)
+# project_id :integer not null
+# created_at :datetime
+# updated_at :datetime
+# active :boolean default(FALSE), not null
+# properties :text
+#
+
+require 'asana'
+
+class AsanaService < Service
+ prop_accessor :api_key, :restrict_to_branch
+ validates :api_key, presence: true, if: :activated?
+
+ def title
+ 'Asana'
+ end
+
+ def description
+ 'Asana - Teamwork without email'
+ end
+
+ def help
+ 'This service adds commit messages as comments to Asana tasks.
+Once enabled, commit messages are checked for Asana task URLs
+(for example, `https://app.asana.com/0/123456/987654`) or task IDs
+starting with # (for example, `#987654`). Every task ID found will
+get the commit comment added to it.
+
+You can also close a task with a message containing: `fix #123456`.
+
+You can find your Api Keys here:
+http://developer.asana.com/documentation/#api_keys'
+ end
+
+ def to_param
+ 'asana'
+ end
+
+ def fields
+ [
+ {
+ type: 'text',
+ name: 'api_key',
+ placeholder: 'User API token. User must have access to task,
+all comments will be attributed to this user.'
+ },
+ {
+ type: 'text',
+ name: 'restrict_to_branch',
+ placeholder: 'Comma-separated list of branches which will be
+automatically inspected. Leave blank to include all branches.'
+ }
+ ]
+ end
+
+ def execute(push)
+ Asana.configure do |client|
+ client.api_key = api_key
+ end
+
+ user = push[:user_name]
+ branch = push[:ref].gsub('refs/heads/', '')
+
+ branch_restriction = restrict_to_branch.to_s
+
+ # check the branch restriction is poplulated and branch is not included
+ if branch_restriction.length > 0 && branch_restriction.index(branch) == nil
+ return
+ end
+
+ project_name = project.name_with_namespace
+ push_msg = user + ' pushed to branch ' + branch + ' of ' + project_name
+
+ push[:commits].each do |commit|
+ check_commit(' ( ' + commit[:url] + ' ): ' + commit[:message], push_msg)
+ end
+ end
+
+ def check_commit(message, push_msg)
+ task_list = []
+ close_list = []
+
+ message.split("\n").each do |line|
+ # look for a task ID or a full Asana url
+ task_list.concat(line.scan(/#(\d+)/))
+ task_list.concat(line.scan(/https:\/\/app\.asana\.com\/\d+\/\d+\/(\d+)/))
+ # look for a word starting with 'fix' followed by a task ID
+ close_list.concat(line.scan(/(fix\w*)\W*#(\d+)/i))
+ end
+
+ # post commit to every taskid found
+ task_list.each do |taskid|
+ task = Asana::Task.find(taskid[0])
+
+ if task
+ task.create_story(text: push_msg + ' ' + message)
+ end
+ end
+
+ # close all tasks that had 'fix(ed/es/ing) #:id' in them
+ close_list.each do |taskid|
+ task = Asana::Task.find(taskid.last)
+
+ if task
+ task.modify(completed: true)
+ end
+ end
+ end
+end
diff --git a/app/views/projects/services/_form.html.haml b/app/views/projects/services/_form.html.haml
index 1151f22c7e8..ba270880881 100644
--- a/app/views/projects/services/_form.html.haml
+++ b/app/views/projects/services/_form.html.haml
@@ -19,7 +19,8 @@
- if @service.help.present?
.bs-callout
- = @service.help
+ = preserve do
+ = markdown @service.help
.form-group
= f.label :active, "Active", class: "control-label"