Class: FlakyTestTracker::Storage::GitHubIssueStorage
- Inherits:
-
Object
- Object
- FlakyTestTracker::Storage::GitHubIssueStorage
- Defined in:
- lib/flaky_test_tracker/storage/github_issue_storage.rb
Overview
Store Test on the GitHub Issue of a GitHub repository.
Constant Summary collapse
- DEFAULT_LABELS =
["flaky test"].freeze
- DEFAULT_TITLE_TEMPLATE =
"Flaky test <%= test.reference %>"
- DEFAULT_BODY_TEMPLATE =
<<~ERB ### Reference <%= test.reference %> ### Description <i><%= test.description %></i> ### Exception <pre><%= test.exception %></pre> ### Failed at <%= test.finished_at %> ### Number occurrences <%= test.number_occurrences %> ### Location [<%= test.location %>](<%= test.source_location_url %>) ERB
Instance Attribute Summary collapse
-
#body_rendering ⇒ #output
Template rendering used to create GitHub Issue body.
-
#client ⇒ #issue #create_issue #update_issue #close_issue
GitHub client.
-
#labels ⇒ Array<String>
GitHub Issue labels used to store tests.
-
#repository ⇒ String
GitHub repository name with organization name or user name.
-
#serializer ⇒ #serialize, #deserialize
The serializer used to store the Test in the GitHub Issue body.
-
#title_rendering ⇒ #output
Template rendering used to create GitHub Issue title.
Class Method Summary collapse
-
.build(client:, repository:, labels: DEFAULT_LABELS, title_template: DEFAULT_TITLE_TEMPLATE, body_template: DEFAULT_BODY_TEMPLATE, serializer: FlakyTestTracker::Serializers::TestHTMLSerializer.new) ⇒ Object
Returns a new instance of GitHubIssueStorage.
Instance Method Summary collapse
- #all ⇒ Array<Test>
- #create(test_input) ⇒ Test
- #delete(id) ⇒ Test
-
#initialize(client:, repository:, labels:, title_rendering:, body_rendering:, serializer:) ⇒ GitHubIssueStorage
constructor
A new instance of GitHubIssueStorage.
- #update(id, test_input) ⇒ Test
Constructor Details
#initialize(client:, repository:, labels:, title_rendering:, body_rendering:, serializer:) ⇒ GitHubIssueStorage
Returns a new instance of GitHubIssueStorage.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/flaky_test_tracker/storage/github_issue_storage.rb', line 73 def initialize( client:, repository:, labels:, title_rendering:, body_rendering:, serializer: ) @client = client @repository = repository @labels = labels @title_rendering = title_rendering @body_rendering = body_rendering @serializer = serializer end |
Instance Attribute Details
#body_rendering ⇒ #output
Template rendering used to create GitHub Issue body.
17 18 19 |
# File 'lib/flaky_test_tracker/storage/github_issue_storage.rb', line 17 def body_rendering @body_rendering end |
#client ⇒ #issue #create_issue #update_issue #close_issue
GitHub client.
17 18 19 |
# File 'lib/flaky_test_tracker/storage/github_issue_storage.rb', line 17 def client @client end |
#labels ⇒ Array<String>
GitHub Issue labels used to store tests.
17 18 19 |
# File 'lib/flaky_test_tracker/storage/github_issue_storage.rb', line 17 def labels @labels end |
#repository ⇒ String
GitHub repository name with organization name or user name. Ex: "masterT/flaky_test_tracker".
17 18 19 |
# File 'lib/flaky_test_tracker/storage/github_issue_storage.rb', line 17 def repository @repository end |
#serializer ⇒ #serialize, #deserialize
The serializer used to store the Test in the GitHub Issue body.
17 18 19 |
# File 'lib/flaky_test_tracker/storage/github_issue_storage.rb', line 17 def serializer @serializer end |
#title_rendering ⇒ #output
Template rendering used to create GitHub Issue title.
17 18 19 |
# File 'lib/flaky_test_tracker/storage/github_issue_storage.rb', line 17 def title_rendering @title_rendering end |
Class Method Details
.build(client:, repository:, labels: DEFAULT_LABELS, title_template: DEFAULT_TITLE_TEMPLATE, body_template: DEFAULT_BODY_TEMPLATE, serializer: FlakyTestTracker::Serializers::TestHTMLSerializer.new) ⇒ Object
Returns a new instance of FlakyTestTracker::Storage::GitHubIssueStorage.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/flaky_test_tracker/storage/github_issue_storage.rb', line 53 def self.build( client:, repository:, labels: DEFAULT_LABELS, title_template: DEFAULT_TITLE_TEMPLATE, body_template: DEFAULT_BODY_TEMPLATE, serializer: FlakyTestTracker::Serializers::TestHTMLSerializer.new ) new( client: Octokit::Client.new(client.merge(auto_paginate: true)), repository: repository, labels: labels, title_rendering: FlakyTestTracker::Rendering.new(template: title_template), body_rendering: FlakyTestTracker::Rendering.new(template: body_template), serializer: serializer ) end |
Instance Method Details
#all ⇒ Array<Test>
90 91 92 93 94 95 96 |
# File 'lib/flaky_test_tracker/storage/github_issue_storage.rb', line 90 def all # See https://octokit.github.io/octokit.rb/Octokit/Client/Issues.html#list_issues-instance_method client .list_issues(repository, { labels: labels.join(",") }) .map { |github_issue| to_model(github_issue) } .compact end |
#create(test_input) ⇒ Test
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/flaky_test_tracker/storage/github_issue_storage.rb', line 99 def create(test_input) test = FlakyTestTracker::Test.new(test_input.serializable_hash) # See https://octokit.github.io/octokit.rb/Octokit/Client/Issues.html#create_issue-instance_method github_issue = client.create_issue( repository, render_title(test: test), render_body(test: test), { labels: labels.join(",") } ) to_model(github_issue) end |
#delete(id) ⇒ Test
127 128 129 130 131 132 133 134 |
# File 'lib/flaky_test_tracker/storage/github_issue_storage.rb', line 127 def delete(id) # See https://octokit.github.io/octokit.rb/Octokit/Client/Issues.html#close_issue-instance_method github_issue = client.close_issue( repository, id ) to_model(github_issue) end |
#update(id, test_input) ⇒ Test
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/flaky_test_tracker/storage/github_issue_storage.rb', line 112 def update(id, test_input) test = FlakyTestTracker::Test.new(test_input.serializable_hash) # See https://octokit.github.io/octokit.rb/Octokit/Client/Issues.html#update_issue-instance_method state = test.resolved? ? "closed" : "open" github_issue = client.update_issue( repository, id, render_title(test: test), render_body(test: test), { labels: labels, state: state } ) to_model(github_issue) end |