lita-github 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd7cf1b35725c7ee19e36efdd1c4717ead4e7dfd
4
- data.tar.gz: dc58dac08313f2ec192911ca292681b146068297
3
+ metadata.gz: 0bca7c5436b3f7d3858b5374d633dbf2ce49a78d
4
+ data.tar.gz: 0f13f80249167fb9cfb48b835c02c377af0994e9
5
5
  SHA512:
6
- metadata.gz: 1f5e87d33ffe37ca8ab4f1b584e32766b649d7a440e7252702d8b27584ea0dcc31e997a446515e7f09ab57daf62290fb03591bfc22578c6d2e146d122d3c4cfd
7
- data.tar.gz: 5f7337752aa592d3c56941cd3ffe4e9e891262875e9e774863e74401b295ac13b7ac800bf9b19fac8d1e03f7ccb5530b59646b0831ebf2e5865220b9397ef8a4
6
+ metadata.gz: d69a87f51a1b4a4d3ce7ad68bc471e29207da530cb192e9d45773a7608d32f1c97f35543030af4b940bc5b9665b5caa609b847232da733ad79ef0a9ef9f99c06
7
+ data.tar.gz: df92f580a280732f33141f74fe5eb8897ac599eb6f876770fb505cea5c777cc4c66af535171db12ac01147e57a09345880f2472048f8cc5fde56046539642677
data/README.md CHANGED
@@ -59,6 +59,8 @@ Here is the current functionality:
59
59
  * `!gh repo delete PagerDuty/lita-github`
60
60
  * Deletes the repo you specify, requires confirmation before doing so
61
61
  * **Note:** This method is disabled by default, you need to enable it by setting `config.handlers.github.repo_delete_enabled = true` in your configuration file
62
+ * `!gh repo rename PagerDuty/lita-github better-lita-github`
63
+ * Renames the repo you specify -- requires confirmation
62
64
  * `!gh repo teams PagerDuty/lita-github`
63
65
  * list all of the teams currently attached to a repo
64
66
  * `!gh repo team add <TEAM_ID|TEAM_SLUG> PagerDuty/lita-github`
@@ -26,6 +26,9 @@ module LitaGithub
26
26
  # key1:value key2:"value2" key3:'a better value'
27
27
  OPT_REGEX ||= /((?:\s+?[a-zA-Z0-9_]+?):(?:(?:".+?")|(?:'.+?')|(?:[a-zA-Z0-9_]+)))/
28
28
 
29
+ # regex matcher for a repo name (not including the org).
30
+ REPO_NAME_REGEX = '(?<repo_name>[a-zA-Z0-9_\-]+)'
31
+
29
32
  # regex matcher for: Org/repo
30
33
  REPO_REGEX = '(?:(?<org>[a-zA-Z0-9_\-]+)(?:\s+?)?\/)?(?:\s+?)?(?<repo>[a-zA-Z0-9_\-]+)'
31
34
  end
@@ -21,7 +21,7 @@
21
21
  # @author Tim Heckman <tim@pagerduty.com>
22
22
  module LitaGithub
23
23
  # lita-github version
24
- VERSION = '0.1.0'
24
+ VERSION = '0.1.1'
25
25
 
26
26
  # lita-github version split amongst different revisions
27
27
  MAJOR_VERSION, MINOR_VERSION, REVISION = VERSION.split('.').map(&:to_i)
@@ -81,6 +81,7 @@ module Lita
81
81
 
82
82
  # Lita::Handlers::GithubRepo
83
83
  config.repo_create_enabled = true
84
+ config.repo_rename_enabled = true
84
85
  config.repo_delete_enabled = false
85
86
  config.repo_team_add_enabled = false
86
87
  config.repo_team_rm_enabled = false
@@ -68,6 +68,17 @@ module Lita
68
68
  }
69
69
  )
70
70
 
71
+ route(
72
+ /#{LitaGithub::R::A_REG}repo\s+?rename\s+?#{LitaGithub::R::REPO_REGEX}\s+?#{LitaGithub::R::REPO_NAME_REGEX}/,
73
+ :repo_rename,
74
+ command: true,
75
+ confirmation: true,
76
+ help: {
77
+ 'gh repo rename PagerDuty/lita-github better-lita-github' =>
78
+ 'Rename the PagerDuty/lita-github repo to PagerDuty/better-lita-github'
79
+ }
80
+ )
81
+
71
82
  route(
72
83
  /#{LitaGithub::R::A_REG}repo\s+?(teams|team\s+?list)\s+?#{LitaGithub::R::REPO_REGEX}/,
73
84
  :repo_teams_list,
@@ -117,6 +128,16 @@ module Lita
117
128
  response.reply(create_repo(org, repo, opts))
118
129
  end
119
130
 
131
+ def repo_rename(response)
132
+ return response.reply(t('method_disabled')) if func_disabled?(__method__)
133
+ org, repo = repo_match(response.match_data)
134
+ new_repo = response.match_data['repo_name']
135
+
136
+ return response.reply(t('not_found', org: org, repo: repo)) unless repo?(rpo(org, repo))
137
+
138
+ response.reply(rename_repo(org, repo, new_repo))
139
+ end
140
+
120
141
  def repo_delete(response)
121
142
  return response.reply(t('method_disabled')) if func_disabled?(__method__)
122
143
 
@@ -308,6 +329,21 @@ module Lita
308
329
  reply
309
330
  end
310
331
 
332
+ def rename_repo(org, repo, new_repo)
333
+ full_name = rpo(org, repo)
334
+ reply = nil
335
+ begin
336
+ octo.edit_repository(full_name, name: new_repo)
337
+ ensure
338
+ if repo?(rpo(org, new_repo))
339
+ reply = t('repo_rename.pass', org: org, old_repo: repo, new_repo: new_repo)
340
+ else
341
+ reply = t('repo_rename.fail', org: org, repo: repo)
342
+ end
343
+ end
344
+ reply
345
+ end
346
+
311
347
  def delete_repo(org, repo)
312
348
  full_name = rpo(org, repo)
313
349
  reply = nil
@@ -26,6 +26,9 @@ en:
26
26
  pass: "Created %{org}/%{repo}: %{repo_url}"
27
27
  fail: "Unable to create %{org}/%{repo}"
28
28
  exists: "Unable to create %{org}/%{repo} as it already exists"
29
+ repo_rename:
30
+ pass: "Renamed %{org}/%{old_repo} to %{org}/%{new_repo}"
31
+ fail: "Unable to rename %{org}/%{repo}"
29
32
  repo_delete:
30
33
  pass: "Deleted %{org}/%{repo}"
31
34
  fail: "Unable to delete %{org}/%{repo}"
@@ -24,6 +24,10 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
24
24
  it { is_expected.to route_command('gh repo new GrapeDuty/lita-test private:true team:heckman').to(:repo_create) }
25
25
  it { is_expected.to route_command('gh repo new GrapeDuty/lita-test private:true randomunparseabletext ').to(:repo_create) }
26
26
 
27
+ # repo_rename command routing
28
+ it { is_expected.to route_command('gh repo rename GrapeDuty/lita-test lita-test-2').to(:repo_rename) }
29
+ it { is_expected.to route_command('gh repo rename lita-test lita-test-2').to(:repo_rename) }
30
+
27
31
  # repo_delete command routing
28
32
  it { is_expected.to route_command('gh repo delete GrapeDuty/lita-test').to(:repo_delete) }
29
33
  it { is_expected.to route_command('gh repo delete lita-test').to(:repo_delete) }
@@ -303,6 +307,34 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
303
307
  end
304
308
  end
305
309
 
310
+ describe '.rename_repo' do
311
+ before do
312
+ allow(github_repo).to receive(:octo).and_return(double('Octokit::Client', edit_repository: nil))
313
+ end
314
+
315
+ context 'when repo renamed' do
316
+ before do
317
+ allow(github_repo).to receive(:repo?).with("#{github_org}/better-lita-test").and_return(true)
318
+ end
319
+
320
+ it 'should confirm successful rename' do
321
+ expect(github_repo.send(:rename_repo, github_org, 'lita-test', 'better-lita-test'))
322
+ .to eql 'Renamed GrapeDuty/lita-test to GrapeDuty/better-lita-test'
323
+ end
324
+ end
325
+
326
+ context 'when repo not renamed' do
327
+ before do
328
+ allow(github_repo).to receive(:repo?).with("#{github_org}/better-lita-test").and_return(false)
329
+ end
330
+
331
+ it 'should reply with failure message' do
332
+ expect(github_repo.send(:rename_repo, github_org, 'lita-test', 'better-lita-test'))
333
+ .to eql 'Unable to rename GrapeDuty/lita-test'
334
+ end
335
+ end
336
+ end
337
+
306
338
  describe '.remove_team_from_repo' do
307
339
  before do
308
340
  @octo_obj = double('Octokit::Client', remove_team_repository: true)
@@ -742,6 +774,41 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
742
774
  end
743
775
  end
744
776
 
777
+ describe '.repo_rename' do
778
+ before do
779
+ allow(github_repo).to receive(:func_disabled?).and_return(false)
780
+ allow(github_repo).to receive(:rename_repo).and_return('hello there')
781
+ allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(true)
782
+ end
783
+
784
+ it 'reply with the return from rename_repo()' do
785
+ send_command("gh repo rename #{github_org}/lita-test better-lita-test")
786
+ expect(replies.last).to eql 'hello there'
787
+ end
788
+
789
+ context 'when command disabled' do
790
+ before do
791
+ allow(github_repo).to receive(:func_disabled?).and_return(true)
792
+ end
793
+
794
+ it 'should no-op and say such if the command is disabled' do
795
+ send_command("gh repo rename #{github_org}/lita-test better-lita-test")
796
+ expect(replies.last).to eql disabled_reply
797
+ end
798
+ end
799
+
800
+ context 'when repo not found' do
801
+ before do
802
+ allow(github_repo).to receive(:repo?).with("#{github_org}/lita-test").and_return(false)
803
+ end
804
+
805
+ it 'should no-op informing you that the repo is not there' do
806
+ send_command("gh repo rename #{github_org}/lita-test better-lita-test")
807
+ expect(replies.last).to eql 'That repo (GrapeDuty/lita-test) was not found'
808
+ end
809
+ end
810
+ end
811
+
745
812
  describe '.repo_teams_list' do
746
813
  before do
747
814
  @teams = [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Heckman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-22 00:00:00.000000000 Z
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler