diff options
| author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2017-04-11 22:34:59 -0300 |
|---|---|---|
| committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2017-04-24 16:17:52 -0300 |
| commit | b43ecca9060b3d7ffd84d700caecf5f35fd403a9 (patch) | |
| tree | 8b23af77d44d2dc854aff7d68179b63867bf5436 /lib/github/representation/branch.rb | |
| parent | fc42f3dffa364a360c76ff2785813d74f42016c7 (diff) | |
| download | gitlab-ce-b43ecca9060b3d7ffd84d700caecf5f35fd403a9.tar.gz | |
Add basic representations for the Github API results
Diffstat (limited to 'lib/github/representation/branch.rb')
| -rw-r--r-- | lib/github/representation/branch.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/github/representation/branch.rb b/lib/github/representation/branch.rb new file mode 100644 index 00000000000..7c65a948ede --- /dev/null +++ b/lib/github/representation/branch.rb @@ -0,0 +1,52 @@ +module Github + module Representation + class Branch < Representation::Base + attr_reader :repository + + def initialize(repository, raw) + @repository = repository + @raw = raw + end + + def user + raw.dig('user', 'login') || 'unknown' + end + + def repo + return @repo if defined?(@repo) + + @repo = Github::Representation::Repo.new(raw['repo']) if raw['repo'].present? + end + + def ref + raw['ref'] + end + + def sha + raw['sha'] + end + + def short_sha + Commit.truncate_sha(sha) + end + + def exists? + branch_exists? && commit_exists? + end + + def valid? + sha.present? && ref.present? + end + + private + + def branch_exists? + repository.branch_exists?(ref) + end + + def commit_exists? + repository.branch_names_contains(sha).include?(ref) + end + end + end +end |
