| lib/septic/scm/log.rb | |
| 23 | @@ -23,7 +23,9 @@ |
| 23 | # Base class for log handlers with common functionality |
| 24 | class Log |
| 25 | # Initialize log db add base class |
| 26 | def initialize(path, revision=nil) |
| 27 | def initialize(user, path, revision=nil) |
| 28 | # User doing the push |
| 29 | @user = user |
| 30 | # Get path |
| 31 | @path = normalize_repository_path(path) |
| 32 | # Cache email to user lookups |
| ... | |
| lib/septic/scm/log_svn.rb | |
| 26 | @@ -26,6 +26,10 @@ |
| 26 | |
| 27 | # Class handling git log parsing and adding to database |
| 28 | class SvnLog < Septic::Scm::Log |
| 29 | def initialize(user) |
| 30 | super(user) |
| 31 | end |
| 32 | |
| 33 | # Update SVN log entries to latest version |
| 34 | def update |
| 35 | # Get repository and current revision |
| ... | |
| integration/scm_git_post_update.rb | |
| 24 | @@ -24,15 +24,18 @@ |
| 24 | |
| 25 | # Check parameters |
| 26 | raise 'GIT_DIR environment not set' unless ENV.include?('GIT_DIR') |
| 27 | raise 'USER environment not set' unless ENV.include?('USER') |
| 28 | raise 'reference not provided as single argument' unless ARGV.size == 1 |
| 29 | |
| 30 | begin |
| 31 | cfg_path = File.join(File.dirname(__FILE__), '..', 'config', 'septic.yml') |
| 32 | cfg = YAML::load_file(cfg_path) |
| 33 | git_dir = File.expand_path(ENV['GIT_DIR']) |
| 34 | login = ENV['USER'] |
| 35 | |
| 36 | params = { 'key' => cfg['services']['key'], 'type' => 'git', |
| 37 | 'path' => git_dir, 'revision' => ARGV[0] } |
| 38 | params = { 'key' => cfg['services']['key'], |
| 39 | 'type' => 'git', 'path' => git_dir, |
| 40 | 'login' => login, 'revision' => ARGV[0] } |
| 41 | |
| 42 | # Setup post request. |
| 43 | url = URI.parse(cfg['site_url'] + '/services/scm_update') |
| ... | |
| test/unit/commit_set_observer_test.rb | |
| 28 | @@ -28,14 +28,14 @@ |
| 28 | task_id = "1" |
| 29 | task = Task.find_by_id(task_id) |
| 30 | assert_equal TaskStatus::NEW, task.task_status_id |
| 31 | assert_equal 0, task.task_change_sets.size |
| 32 | assert_equal 1, task.task_change_sets.size |
| 33 | assert_equal 0, task.task_changes.size |
| 34 | |
| 35 | observer.send :task_close, commit, task_id |
| 36 | |
| 37 | task = Task.find_by_id(task_id) |
| 38 | assert_equal TaskStatus::CLOSED, task.task_status_id |
| 39 | assert_equal 1, task.task_change_sets.size |
| 40 | assert_equal 2, task.task_change_sets.size |
| 41 | assert_equal 2, task.task_changes.size |
| 42 | end |
| 43 | |
| ... | |
| 46 | @@ -46,14 +46,14 @@ |
| 46 | task_id = "2" |
| 47 | task = Task.find_by_id(task_id) |
| 48 | assert_equal TaskStatus::CLOSED, task.task_status_id |
| 49 | assert_equal 0, task.task_change_sets.size |
| 50 | assert_equal 1, task.task_change_sets.size |
| 51 | assert_equal 0, task.task_changes.size |
| 52 | |
| 53 | observer.send :task_close, commit, task_id |
| 54 | |
| 55 | task = Task.find_by_id(task_id) |
| 56 | assert_equal TaskStatus::CLOSED, task.task_status_id |
| 57 | assert_equal 0, task.task_change_sets.size |
| 58 | assert_equal 1, task.task_change_sets.size |
| 59 | assert_equal 0, task.task_changes.size |
| 60 | end |
| 61 | |
| ... | |
| 65 | @@ -65,13 +65,13 @@ |
| 65 | task_id = "1" |
| 66 | task = Task.find_by_id(task_id) |
| 67 | assert_equal TaskStatus::NEW, task.task_status_id |
| 68 | assert_equal 0, task.task_change_sets.size |
| 69 | assert_equal 1, task.task_change_sets.size |
| 70 | assert_equal 0, task.task_changes.size |
| 71 | |
| 72 | observer.send :task_comment, commit, task_id |
| 73 | |
| 74 | task = Task.find_by_id(task_id) |
| 75 | assert_equal 1, task.task_change_sets.size |
| 76 | assert_equal 2, task.task_change_sets.size |
| 77 | assert_equal 1, task.task_changes.size |
| 78 | end |
| 79 | |
| ... | |
| lib/septic/scm/log_git.rb | |
| 25 | @@ -25,14 +25,14 @@ |
| 25 | # Class handling git log parsing and adding to database |
| 26 | class LogGit < Septic::Scm::Log |
| 27 | # Initialize git log |
| 28 | def initialize(path, reference) |
| 29 | super |
| 30 | def initialize(user, path, reference) |
| 31 | super(user, path, reference) |
| 32 | |
| 33 | # Parse reference, sets where and branch |
| 34 | parse_reference(reference) |
| 35 | end |
| 36 | |
| 37 | def update |
| 38 | def update |
| 39 | raise "can only update to heads not #{@where}" unless @where == 'heads' |
| 40 | |
| 41 | # Get repository for commit |
| ... | |
| 56 | @@ -56,19 +56,24 @@ |
| 56 | commits_data.reverse_each do |commit_data| |
| 57 | add_commit(commit_set, commit_data) |
| 58 | end |
| 59 | commit_set.reload |
| 60 | commit_set.save |
| 61 | |
| 62 | commit_set |
| 63 | end |
| 64 | |
| 65 | def add_commit(commit_set, commit_data) |
| 66 | commit_data['commit_set_id'] = commit_set.id |
| 67 | commit_data['repository_id'] = commit_set.repository.id |
| 68 | |
| 69 | # Split body / files, lookup user and create commit |
| 70 | commit_data['body'], commit_files = parse_body_files(commit_data['body']) |
| 71 | user = get_user_from_email(commit_data['email']) |
| 72 | if user |
| 73 | commit_data['user_id'] = user.id |
| 74 | end |
| 75 | commit = commit_set.commits.create(commit_data) |
| 76 | |
| 77 | commit = CommitGit.create(commit_data) |
| 78 | |
| 79 | # Add commit files |
| 80 | if commit.valid? |
| ... | |
| 84 | @@ -79,7 +84,7 @@ |
| 84 | # Update commit links |
| 85 | set_revision_relations(commit) |
| 86 | else |
| 82 | raise "failed creating commit with errors %s" % commit.errors.full_messages.join('\n') |
| 88 | raise "failed creating commit for %s with errors %s" % [commit.revision, commit.errors.full_messages.join('\n')] |
| 89 | end |
| 90 | end |
| 91 | |
| ... | |
| app/models/commit_set_observer.rb | |
| 8 | @@ -8,7 +8,7 @@ |
| 8 | # Regular expression matching ticket comment |
| 9 | @@RE_COMMENT = Regexp.new('comment:?\s+#([0-9]+)', Regexp::IGNORECASE) |
| 10 | |
| 11 | def after_create(commit_set) |
| 12 | def after_save(commit_set) |
| 13 | return if commit_set.commits.empty? |
| 14 | |
| 15 | commit_set.commits.each do |commit| |
| ... | |
| 43 | @@ -43,6 +43,7 @@ |
| 43 | :user_id => commit.user_id) |
| 44 | task_change_comment = task_change_set.task_changes.create( |
| 45 | :task_id => task.id, :user_id => commit.user_id, |
| 46 | :field => 'comment', |
| 47 | :value_after => create_close_msg(commit)) |
| 48 | task_change_close = task_change_set.task_changes.create( |
| 49 | :task_id => task.id, :user_id => commit.user_id, |
| ... | |
| 57 | @@ -56,7 +57,7 @@ |
| 57 | end |
| 58 | |
| 59 | def create_close_msg(commit) |
| 59 | return "Close from commit [[Commit:#{commit.id}|#{commit.revision}]] \"#{commit.title}\" by [[User:#{commit.user.login}|#{commit.user.name}]]" |
| 61 | return "Close from commit: [[Commit:#{commit.id}|#{commit.revision}]] by [[User:#{commit.user.login}|#{commit.user.name}]]" |
| 62 | end |
| 63 | |
| 64 | def task_comment(commit, task_id) |
| ... | |
| app/controllers/services_controller.rb | |
| 33 | @@ -33,15 +33,19 @@ |
| 33 | require_key |
| 34 | |
| 35 | @type = params['type'] |
| 36 | raise 'unknown type' unless @@SUPPORTED_SCM_TYPES.include?(params['type']) |
| 37 | raise 'unknown type' unless @@SUPPORTED_SCM_TYPES.include?(params['type']) |
| 38 | raise 'missing parameter path' unless params.include?('path') |
| 39 | raise 'missing parameter revision' unless params.include?('revision') |
| 40 | raise 'missing parameter login' unless params.include?('login') |
| 41 | |
| 42 | @user = User.find_by_email(params['login']) |
| 43 | raise "invalid user #{params['login']}" if @user.nil? |
| 44 | |
| 45 | # Initialize log |
| 46 | if @type == 'git' |
| 47 | log = Septic::Scm::LogGit.new(params['path'], params['revision']) |
| 48 | log = Septic::Scm::LogGit.new(@user, params['path'], params['revision']) |
| 49 | elsif @type == 'svn' |
| 50 | log = Septic::Scm::LogSvn.new(params['path'], params['revision']) |
| 51 | log = Septic::Scm::LogSvn.new(@user, params['path'], params['revision']) |
| 52 | end |
| 53 | |
| 54 | # Update log |
| ... | |
| 53 | @@ -49,7 +53,7 @@ |
| 53 | if commit_set.nil? |
| 54 | message = 'no changes in repository' |
| 55 | else |
| 52 | message = 'log updated with %d new entries' % [commits.size] |
| 57 | message = 'log updated with %d new entries' % [commit_set.commits.size] |
| 58 | end |
| 59 | |
| 60 | status = 200 |
| ... | |