Class: TFSGraph::Branch
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: Time},
type: {default: "Feature", type: Integer},
archived: {default: false, type: String},
hidden: {default: false, type: String},
last_updated: {type: Time, default: Time.at(0).utc}
}
- BRANCH_TYPES =
[
:master,
:release,
:feature
]
- ARCHIVED_FLAGS =
["Archive"]
- RELEASE_MATCHER =
/^(.+)-r(\d+)-(\d+)$/i
PersistableEntity::NotPersisted
Instance Attribute Summary
#db_object, #id
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
#delete!, #persist, #persisted?, repository, #save!, #to_hash
Methods included from Extensions
#base_class_name
Methods inherited from Entity
inherited, #schema, #to_hash
Constructor Details
#initialize(repo, args) ⇒ Branch
Returns a new instance of Branch.
32
33
34
35
36
37
|
# File 'lib/tfs_graph/branch.rb', line 32
def initialize(repo, args)
super
detect_type
detect_archived
end
|
Instance Method Details
#<=>(other) ⇒ Object
166
167
168
|
# File 'lib/tfs_graph/branch.rb', line 166
def <=>(other)
path <=> other.path
end
|
#absolute_root ⇒ Object
93
94
95
|
# File 'lib/tfs_graph/branch.rb', line 93
def absolute_root
@absolute_root ||= @repo.absolute_root_for(self)
end
|
#active? ⇒ Boolean
61
62
63
|
# File 'lib/tfs_graph/branch.rb', line 61
def active?
!hidden? && !archived?
end
|
#add_changeset(changeset) ⇒ Object
110
111
112
113
114
115
116
|
# File 'lib/tfs_graph/branch.rb', line 110
def add_changeset(changeset)
changeset.branch_path = self.path
changeset.save!
@repo.relate(:changesets, self.db_object, changeset.db_object)
end
|
#add_child(changeset) ⇒ Object
118
119
120
|
# File 'lib/tfs_graph/branch.rb', line 118
def add_child(changeset)
@repo.relate(:child, self.db_object, changeset.db_object)
end
|
#ahead_of_master ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/tfs_graph/branch.rb', line 138
def ahead_of_master
return 0 unless absolute_root
my_changes = changesets
root_changes = absolute_root.merged_changesets
intersect = root_changes & my_changes
diff = my_changes - intersect
diff.count
end
|
#archive! ⇒ Object
83
84
85
86
|
# File 'lib/tfs_graph/branch.rb', line 83
def archive!
self.archived = true
save!
end
|
#archived ⇒ Object
45
46
47
|
# File 'lib/tfs_graph/branch.rb', line 45
def archived
@archived.to_s
end
|
#archived? ⇒ Boolean
53
54
55
|
# File 'lib/tfs_graph/branch.rb', line 53
def archived?
archived.to_s == "true"
end
|
#as_json(options = {}) ⇒ Object
170
171
172
173
174
175
176
|
# File 'lib/tfs_graph/branch.rb', line 170
def as_json(options={})
results = super
results[:related_branches] = related_branches
results[:id] = id
results
end
|
#behind_master ⇒ Object
gets the set of changesets that exist in both root and self then gets a diff of that set and the root.
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/tfs_graph/branch.rb', line 153
def behind_master
return 0 unless absolute_root
my_changes = merged_changesets
root_changes = absolute_root.changesets
intersect = my_changes & root_changes
diff = root_changes - intersect
diff.count
end
|
#branch? ⇒ Boolean
97
98
99
|
# File 'lib/tfs_graph/branch.rb', line 97
def branch?
!master?
end
|
#changesets ⇒ Object
122
123
124
|
# File 'lib/tfs_graph/branch.rb', line 122
def changesets
@repo.get_nodes(db_object, :outgoing, :changesets, Changeset)
end
|
#contributors ⇒ Object
126
127
128
|
# File 'lib/tfs_graph/branch.rb', line 126
def contributors
changesets.group_by(&:committer)
end
|
#hidden ⇒ Object
49
50
51
|
# File 'lib/tfs_graph/branch.rb', line 49
def hidden
@hidden.to_s
end
|
#hidden? ⇒ Boolean
57
58
59
|
# File 'lib/tfs_graph/branch.rb', line 57
def hidden?
hidden.to_s == "true"
end
|
#hide! ⇒ Object
78
79
80
81
|
# File 'lib/tfs_graph/branch.rb', line 78
def hide!
self.hidden = true
save!
end
|
#last_changeset ⇒ Object
134
135
136
|
# File 'lib/tfs_graph/branch.rb', line 134
def last_changeset
changesets.last
end
|
#merged_changesets ⇒ Object
106
107
108
|
# File 'lib/tfs_graph/branch.rb', line 106
def merged_changesets
@repo.get_nodes(db_object, :outgoing, :included, Changeset)
end
|
#named_type ⇒ Object
65
66
67
|
# File 'lib/tfs_graph/branch.rb', line 65
def named_type
BRANCH_TYPES[type]
end
|
branches this one touches or is touched
102
103
104
|
# File 'lib/tfs_graph/branch.rb', line 102
def related_branches
@repo.get_nodes(db_object, :incoming, :related, Branch).map &:id
end
|
#root_changeset ⇒ Object
130
131
132
|
# File 'lib/tfs_graph/branch.rb', line 130
def root_changeset
@root = @repo.get_nodes(db_object, :outgoing, :child, Changeset).first if (@root.nil? || @root.empty?)
end
|
#rootless? ⇒ Boolean
88
89
90
|
# File 'lib/tfs_graph/branch.rb', line 88
def rootless?
!master? && root.empty?
end
|
#type_index(name) ⇒ Object
178
179
180
|
# File 'lib/tfs_graph/branch.rb', line 178
def type_index(name)
BRANCH_TYPES.index(name.to_sym)
end
|
#updated! ⇒ Object
69
70
71
72
|
# File 'lib/tfs_graph/branch.rb', line 69
def updated!
@last_updated = Time.now.utc
save!
end
|
#updated_since?(date) ⇒ Boolean
74
75
76
|
# File 'lib/tfs_graph/branch.rb', line 74
def updated_since?(date)
@last_updated > date
end
|