Class: Fbe::FakeOctokit

Inherits:
Object
  • Object
show all
Defined in:
lib/fbe/octo.rb

Overview

Fake GitHub client, for tests.

Instance Method Summary collapse

Instance Method Details

#add_comment(_repo, _issue, _text) ⇒ Object



178
179
180
181
182
# File 'lib/fbe/octo.rb', line 178

def add_comment(_repo, _issue, _text)
  {
    id: 42
  }
end

#issue_timeline(_repo, _issue, _options = {}) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/fbe/octo.rb', line 199

def issue_timeline(_repo, _issue, _options = {})
  [
    {
      event: 'renamed',
      actor: {
        id: 888,
        login: 'torvalds'
      },
      repository: {
        id: name_to_number('yegor256/judges'),
        full_name: 'yegor256/judges'
      },
      rename: {
        from: 'before',
        to: 'after'
      },
      created_at: random_time
    },
    {
      event: 'labeled',
      actor: {
        id: 888,
        login: 'torvalds'
      },
      repository: {
        id: name_to_number('yegor256/judges'),
        full_name: 'yegor256/judges'
      },
      label: {
        name: 'bug'
      },
      created_at: random_time
    }
  ]
end

#name_to_number(name) ⇒ Object



112
113
114
115
# File 'lib/fbe/octo.rb', line 112

def name_to_number(name)
  return name unless name.is_a?(String)
  name.chars.map(&:ord).inject(0, :+)
end

#random_timeObject



108
109
110
# File 'lib/fbe/octo.rb', line 108

def random_time
  Time.now - rand(10_000)
end

#rate_limitObject



117
118
119
120
121
122
123
# File 'lib/fbe/octo.rb', line 117

def rate_limit
  o = Object.new
  def o.remaining
    100
  end
  o
end

#repositories(_user = nil) ⇒ Object



125
126
127
128
129
130
# File 'lib/fbe/octo.rb', line 125

def repositories(_user = nil)
  [
    repository('yegor256/judges'),
    repository('yegor256/factbase')
  ]
end

#repository(name) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/fbe/octo.rb', line 140

def repository(name)
  {
    id: name_to_number(name),
    full_name: name.is_a?(Integer) ? 'yegor256/test' : name,
    default_branch: 'master',
    private: false,
    owner: { login: name.to_s.split('/')[0], id: 526_301, site_admin: false },
    html_url: "https://github.com/#{name}",
    description: 'something',
    fork: false,
    url: "https://github.com/#{name}",
    created_at: random_time,
    updated_at: random_time,
    pushed_at: random_time,
    size: 470,
    stargazers_count: 1,
    watchers_count: 1,
    language: 'Ruby',
    has_issues: true,
    has_projects: true,
    has_downloads: true,
    has_wiki: true,
    has_pages: false,
    has_discussions: false,
    forks_count: 0,
    archived: false,
    disabled: false,
    open_issues_count: 6,
    license: { key: 'mit', name: 'MIT License' },
    allow_forking: true,
    is_template: false,
    visibility: 'public',
    forks: 0,
    open_issues: 6,
    watchers: 1
  }
end

#repository_events(repo, _options = {}) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/fbe/octo.rb', line 235

def repository_events(repo, _options = {})
  [
    {
      id: '123',
      type: 'PushEvent',
      repo: {
        id: name_to_number(repo),
        name: repo,
        url: "https://api.github.com/repos/#{repo}"
      },
      payload: {
        push_id: 42,
        ref: 'refs/heads/master',
        size: 1,
        distinct_size: 0,
        head: 'b7089c51cc2526a0d2619d35379f921d53c72731',
        before: '12d3bff1a55bad50ee2e8f29ade7f1c1e07bb025'
      },
      actor: {
        id: 888,
        login: 'torvalds',
        display_login: 'torvalds'
      },
      created_at: random_time,
      public: true
    },
    {
      id: '124',
      type: 'IssuesEvent',
      repo: {
        id: name_to_number(repo),
        name: repo,
        url: "https://api.github.com/repos/#{repo}"
      },
      payload: {
        action: 'closed',
        issue: {
          number: 42
        }
      },
      actor: {
        id: 888,
        login: 'torvalds',
        display_login: 'torvalds'
      },
      created_at: random_time,
      public: true
    },
    {
      id: '125',
      type: 'IssuesEvent',
      repo: {
        id: name_to_number(repo),
        name: repo,
        url: "https://api.github.com/repos/#{repo}"
      },
      payload: {
        action: 'opened',
        issue: {
          number: 42
        }
      },
      actor: {
        id: 888,
        login: 'torvalds',
        display_login: 'torvalds'
      },
      created_at: random_time,
      public: true
    }
  ]
end

#search_issues(_query, _options = {}) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/fbe/octo.rb', line 184

def search_issues(_query, _options = {})
  {
    items: [
      {
        number: 42,
        labels: [
          {
            name: 'bug'
          }
        ]
      }
    ]
  }
end

#user(name) ⇒ Object



132
133
134
135
136
137
138
# File 'lib/fbe/octo.rb', line 132

def user(name)
  {
    id: 444,
    login: 'yegor256',
    type: name == 29_139_614 ? 'Bot' : 'User'
  }
end