Module: GitFusion::Util

Includes:
HelixVersioningEngine
Included in:
App, ConfigParser
Defined in:
lib/git_fusion/util.rb

Overview

namespace for functions supporting git-fusion api

Constant Summary

REPO_INITIALISED =

Messages back to client

'Repository already initialised'
PATCH_PARAMS_DONT_EXIST =
'Chosen repo configuration' \
'p4gf_file does not have all of the specified parameters'
KEY_ALREADY_EXISTS =
'Key under this name already uploaded, ' \
'choose a different name'
USER_NOT_MATCHING =
'User is authenticated, ' \
'but not authorised to view the requested data.'
DF_MATCH =
%r{\/\/(?<depot>.*)\/users\/(?<user>.*)\/keys\/(?<key_name>.*)$}

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from HelixVersioningEngine

invalid_user_email?

Class Method Details

+ (Boolean) error?(p4)

Returns:

  • (Boolean)


60
61
62
# File 'lib/git_fusion/util.rb', line 60

def self.error?(p4)
  !p4.errors.empty?
end

Instance Method Details

- (Object) all_keys



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/git_fusion/util.rb', line 27

def all_keys
  p4, hws_settings = temp_client
  file_list = p4.run_files('-e',
                           "//#{hws_settings.GIT_FUSION_DEPOT}/users/*/...")

  file_list.map do |file|
    data = file['depotFile'].match(DF_MATCH)
    { 'key_name' => GitFusionStrings.decode(data['key_name']),
      'user' => data['user'],
      'key' => print_result(file['depotFile'], p4: p4) }
  end
end

- (Object) check_if_key_exists(key)



45
46
47
48
# File 'lib/git_fusion/util.rb', line 45

def check_if_key_exists(key)
  keys = all_keys
  keys.any? { |h| h['key'] == key }
end

- (Object) check_if_key_name_exists(key, user)



50
51
52
53
# File 'lib/git_fusion/util.rb', line 50

def check_if_key_name_exists(key, user)
  keys = all_keys
  keys.any? { |h| h['key_name'] == key && h['user'] == user }
end

- (Object) decode_from_uri(*args)



87
88
89
90
91
# File 'lib/git_fusion/util.rb', line 87

def decode_from_uri(*args)
  args.map do |a|
    HWSStrings.component_decode(a, '%', GitFusionStrings::URI_RESERVED_CHARACTERS)
  end
end

- (Object) encode_to_gf_format(*args)



93
94
95
96
97
# File 'lib/git_fusion/util.rb', line 93

def encode_to_gf_format(*args)
  args.map do |a|
    GitFusionStrings.encode(a)
  end
end

- (Object) error_and_clean_up(error)



72
73
74
# File 'lib/git_fusion/util.rb', line 72

def error_and_clean_up(error)
  halt 400, to_message(error).to_json
end

- (Object) get_by_key(key, value)



55
56
57
58
# File 'lib/git_fusion/util.rb', line 55

def get_by_key(key, value)
  val = all_keys.select { |record| record['key'] == key }
  val.first.nil? ? '' : val.first[value]
end

- (Object) keys_for_user(user)



40
41
42
43
# File 'lib/git_fusion/util.rb', line 40

def keys_for_user(user)
  keys = all_keys.select { |key| key['user'] == user }
  keys
end


76
77
78
79
80
81
82
83
84
85
# File 'lib/git_fusion/util.rb', line 76

def print_result(file_location, p4: nil)
  p4 = temp_client.first unless p4

  file_result = p4.run_print(file_location)
  content = ''.b
  file_result.drop(1).each do |result|
    content << result if result
  end
  content
end

- (Object) submit_file(p4, file_path, file_content, description)



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/git_fusion/util.rb', line 99

def submit_file(p4, file_path, file_content, description)
  files = [
    ChangeService::File.new(depot_file: file_path,
                            action: 'upload',
                            content: file_content)
  ]

  change_service = ChangeService.new(p4: p4,
                                     client_root: env['p4_root'],
                                     client_name: p4.client)

  change_service.submit(files: files,
                        description: description)
end

- (Object) temp_client



21
22
23
24
25
# File 'lib/git_fusion/util.rb', line 21

def temp_client
  require_p4_with_temp_client

  [env['p4'], env['hws_settings']]
end

- (Object) to_message(message)



64
65
66
67
68
69
70
# File 'lib/git_fusion/util.rb', line 64

def to_message(message)
  {
    MessageCode: 0,
    MessageSeverity: 3,
    MessageText: message
  }
end