Class: TFSGraph::Branch

Inherits:
Entity
  • Object
show all
Extended by:
Comparable, TFSHelpers
Defined in:
lib/tfs_graph/branch.rb

Constant Summary collapse

SCHEMA =
{
  original_path: {key: "Path", type: String},
  path: {key: "Path", converter: ->(path) { repath_archive(path) }, type: String},
  project: {converter: ->(path) { branch_project(path) }, key: "Path", type: String},
  name: {converter: ->(path) { branch_path_to_name(path) }, key: "Path", type: String},
  root: {converter: ->(path) { repath_archive(server_path_to_odata_path(path)) if path }, key: "ParentBranch", type: String},
  created: {key: "DateCreated", type: DateTime},
  type: {default: "Feature", type: Integer},
  archived: {default: false, type: String},
  hidden: {default: false, type: String}
}
BRANCH_TYPES =
[
  :master,
  :release,
  :feature
]
ARCHIVED_FLAGS =
["Archive"]
RELEASE_MATCHER =
/^(.+)-r(\d+)-(\d+)$/i

Instance Method Summary collapse

Methods included from TFSHelpers

base_username, branch_base, branch_path_to_name, branch_project, odata_path_to_server_path, scrub_changeset, server_path_to_odata_path

Methods inherited from Entity

inherited

Instance Method Details

#<=>(other) ⇒ Object



127
128
129
# File 'lib/tfs_graph/branch.rb', line 127

def <=>(other)
  path <=> other.path
end

#absolute_rootObject

returns a branch



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/tfs_graph/branch.rb', line 71

def absolute_root
  @absolute_root ||= begin
    item = self
    proj = ProjectStore.find_cached project

    until(item.master?) do
      item = proj.branches.detect {|branch| branch.path == item.root }
    end

    item
  end
end

#ahead_of_masterObject



109
110
111
112
113
114
115
# File 'lib/tfs_graph/branch.rb', line 109

def ahead_of_master
  return 0 unless absolute_root
  self.outgoing(:changesets)
    .diff(absolute_root.outgoing(:included)
      .intersect(self.outgoing(:changesets)))
    .to_a.count
end

#archive!Object



57
58
59
60
# File 'lib/tfs_graph/branch.rb', line 57

def archive!
  self.archived = true
  save
end

#archived?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/tfs_graph/branch.rb', line 40

def archived?
  archived.to_s == "true"
end

#as_json(options = {}) ⇒ Object



131
132
133
134
# File 'lib/tfs_graph/branch.rb', line 131

def as_json(options={})
  options.merge! methods: :related_branches
  super
end

#behind_masterObject

gets the set of changesets that exist in both root and self then gets a diff of that set and the root.



119
120
121
122
123
124
125
# File 'lib/tfs_graph/branch.rb', line 119

def behind_master
  return 0 unless absolute_root
  absolute_root.outgoing(:changesets)
    .diff(self.outgoing(:included)
      .intersect(absolute_root.outgoing(:changesets)))
    .to_a.count
end

#branch?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/tfs_graph/branch.rb', line 84

def branch?
  !master?
end

#changesetsObject



93
94
95
# File 'lib/tfs_graph/branch.rb', line 93

def changesets
  outgoing(:changesets).options(model: Changeset).nodes.to_a
end

#contributorsObject



97
98
99
# File 'lib/tfs_graph/branch.rb', line 97

def contributors
  changesets.group_by(&:committer)
end

#hidden?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/tfs_graph/branch.rb', line 44

def hidden?
  hidden.to_s == "true"
end

#hide!Object



52
53
54
55
# File 'lib/tfs_graph/branch.rb', line 52

def hide!
  self.hidden = true
  save
end

#last_changesetObject



105
106
107
# File 'lib/tfs_graph/branch.rb', line 105

def last_changeset
  changesets.last
end

#named_typeObject



48
49
50
# File 'lib/tfs_graph/branch.rb', line 48

def named_type
  BRANCH_TYPES[type]
end

branches this one touches or is touched



89
90
91
# File 'lib/tfs_graph/branch.rb', line 89

def related_branches
  incoming(:related).options(model: Branch).nodes.to_a.map &:id
end

#root_changesetObject



101
102
103
# File 'lib/tfs_graph/branch.rb', line 101

def root_changeset
  @root ||= outgoing(:child).options(model: Changeset).nodes.to_a.first
end

#rootless?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/tfs_graph/branch.rb', line 62

def rootless?
  !master? && root.empty?
end

#type_index(name) ⇒ Object



66
67
68
# File 'lib/tfs_graph/branch.rb', line 66

def type_index(name)
  BRANCH_TYPES.index(name.to_sym)
end