Skip to content

Commit

Permalink
refs #1 Octokit::Errorのエラーハンドリングを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
xketanaka committed Sep 28, 2023
1 parent d29210e commit e447984
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/redmine/scm/adapters/github_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def branches
end
end
@branches.sort!
rescue Octokit::Error => e
raise CommandFailed, handle_octokit_error(e)
end

def entries(path=nil, identifier=nil, options={})
Expand All @@ -59,10 +61,14 @@ def entries(path=nil, identifier=nil, options={})
end
end
entries.sort_by_name
rescue Octokit::Error => e
raise CommandFailed, handle_octokit_error(e)
end

def rev_2_sha(rev)
Octokit.commits(@repos, rev, { per_page: 1 }).map(&:sha).first
rescue Octokit::Error => e
raise CommandFailed, handle_octokit_error(e)
end

def lastrev(path, rev)
Expand All @@ -79,12 +85,16 @@ def lastrev(path, rev)
})
end
return nil
rescue Octokit::Error => e
raise CommandFailed, handle_octokit_error(e)
end

def get_path_name(path)
Octokit.commits(@repos).map do |c|
Octokit.tree(@repos, c.commit.tree.sha).tree.map{|b| [b.sha, b.path] }
end.flatten.each_slice(2).to_h[path]
rescue Octokit::Error => e
raise CommandFailed, handle_octokit_error(e)
end

def revisions(path, identifier_from, identifier_to, options={})
Expand Down Expand Up @@ -147,6 +157,8 @@ def revisions(path, identifier_from, identifier_to, options={})
revs = revs.reverse.sort do |a, b|
a.time <=> b.time
end
rescue Octokit::Error => e
raise CommandFailed, handle_octokit_error(e)
end

def get_filechanges_and_append_to(revisions)
Expand All @@ -171,6 +183,8 @@ def get_filechanges_and_append_to(revisions)
end
revision.paths = files
end
rescue Octokit::Error => e
raise CommandFailed, handle_octokit_error(e)
end

def diff(path, identifier_from, identifier_to=nil)
Expand Down Expand Up @@ -218,6 +232,8 @@ def diff(path, identifier_from, identifier_to=nil)
end
diff.flatten!
diff.deep_dup
rescue Octokit::Error => e
raise CommandFailed, handle_octokit_error(e)
end

def annotate(path, identifier=nil)
Expand Down Expand Up @@ -269,12 +285,20 @@ def cat(path, identifier=nil)

content = blob.encoding == "base64" ? Base64.decode64(blob.content) : blob.content
content.force_encoding 'utf-8'
rescue Octokit::Error => e
raise CommandFailed, handle_octokit_error(e)
end

def valid_name?(name)
true
end

def handle_octokit_error(e)
logger.error "scm: github: error: #{e.message}"
gh_error = JSON.parse(e.response_body.to_s)['message'].presence
gh_error ? 'error response from GitHub: ' + gh_error : ''
end

end # end GitHubAdapter
end # end Adapters
end # end Scm
Expand Down

0 comments on commit e447984

Please sign in to comment.