cimas 0.1.3 → 0.1.4

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
  SHA256:
3
- metadata.gz: 9394871c2e095def57e7674194b7a43239da13230d5e5ff6c1278258deae56da
4
- data.tar.gz: de2bfd5e44818ca43dcccdfc3a965542edf1c3352ce120c462182ee30a525427
3
+ metadata.gz: 914081d7dffac8d44caecd31568adc36ca7b87d1493cdd90840d3f53e44d5f9d
4
+ data.tar.gz: 78d8cf640851b093868598702abd538c9b239f7614eba62525de249b572d4704
5
5
  SHA512:
6
- metadata.gz: 8df40444ecb07044787e228c2a3998fcb3432db947b84d71f70e0c8d0783f137ece83e22d9a9d5604b634123c3ef3a15a050abd96360ac82be3c4f3bf6733e5a
7
- data.tar.gz: 63fdae72e4738e64dd29b15ee2332f49bb842c885f8056f52dce8ff2bac3b4e9646ac14bead264f859acd4c0974e1263ef9c8fe6a03f8dc598bef41961af0a34
6
+ metadata.gz: fb099628d653c820358e6e6ad4c4458e96e187dbe7e04613842e434dd12ad322ab92d7352713dbfdb4c2deb1fb036c96ac44714b87c88cf30ca01affdc57b8c4
7
+ data.tar.gz: 4fa7ebbe5c44d21a33134571637da703aaca216545ecd6ab441e640c184c231a9e884f74966088d0029457b3896b0c1d602765e028f91867ad896db6cada3626
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cimas (0.1.0)
4
+ cimas (0.1.3)
5
5
  git
6
6
  octokit
7
7
  travis
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
@@ -1,7 +1,5 @@
1
-
2
1
  lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "cimas"
5
3
  require "cimas/version"
6
4
 
7
5
  Gem::Specification.new do |spec|
data/exe/cimas CHANGED
@@ -150,10 +150,10 @@ subcommands = {
150
150
  opts.on("-g GROUP1,GROUP2,GROUPX", Array, "Groups to update") do |groups|
151
151
  options['groups'] = groups
152
152
  end
153
- # TODO: implement
154
- # opts.on("--force", "Force push (with commit amend)") do |force|
155
- # options['force_push'] = force
156
- # end
153
+
154
+ opts.on("--force", "Force push (with commit amend)") do |force|
155
+ options['force_push'] = force
156
+ end
157
157
  end,
158
158
  'open-prs' => OptionParser.new do |opts|
159
159
  opts.banner = "Usage: cimas open-pr [options]"
@@ -1,5 +1,13 @@
1
- require "cimas/cli/command"
2
1
  require "cimas/version"
2
+ require "cimas/cli/command"
3
+ require "cimas/repository"
3
4
 
4
5
  module Cimas
6
+ def self.root
7
+ File.dirname(__dir__)
8
+ end
9
+
10
+ def self.root_path
11
+ Pathname.new(Cimas.root)
12
+ end
5
13
  end
@@ -2,6 +2,7 @@ require 'json'
2
2
  require 'yaml'
3
3
  require 'net/http'
4
4
  require 'git'
5
+ require 'cimas'
5
6
  # require 'travis/client/session'
6
7
 
7
8
  module Cimas
@@ -113,9 +114,6 @@ module Cimas
113
114
  next
114
115
  end
115
116
 
116
- branch = repo['branch']
117
- files = repo['files']
118
-
119
117
  repo_dir = File.join(repos_path, repo_name)
120
118
  unless File.exist?(repo_dir)
121
119
  puts "[ERROR] #{repo_name} is missing in #{repos_path}, skipping sync for it."
@@ -124,13 +122,13 @@ module Cimas
124
122
 
125
123
  dry_run("Copying files to #{repo_name} and staging them") do
126
124
  g = Git.open(repo_dir)
127
- g.checkout(branch)
128
- g.reset_hard(branch)
125
+ g.checkout(repo.branch)
126
+ g.reset_hard(repo.branch)
129
127
  g.clean(force: true)
130
128
 
131
129
  puts "Syncing and staging files in #{repo_name}..."
132
130
 
133
- files.each do |target, source|
131
+ repo.files.each do |target, source|
134
132
  # puts "file #{source} => #{target}"
135
133
  source_path = File.join(config_master_path, source)
136
134
  target_path = File.join(repos_path, repo_name, target)
@@ -163,9 +161,6 @@ module Cimas
163
161
  next
164
162
  end
165
163
 
166
- branch = repo['branch']
167
- files = repo['files']
168
-
169
164
  repo_dir = File.join(repos_path, repo_name)
170
165
  unless File.exist?(repo_dir)
171
166
  puts "[ERROR] #{repo_name} is missing in #{repos_path}, skipping diff for it."
@@ -247,8 +242,7 @@ module Cimas
247
242
  end
248
243
 
249
244
  def repo_by_name(name)
250
- # puts "getting repository for #{name}"
251
- data['repositories'][name]
245
+ Cimas::Repository.new(name, data["repositories"][name])
252
246
  end
253
247
 
254
248
  def pull
@@ -256,17 +250,19 @@ module Cimas
256
250
  filtered_repo_names.each do |repo_name|
257
251
 
258
252
  repo = repo_by_name(repo_name)
253
+
259
254
  if repo.nil?
260
255
  puts "[WARNING] #{repo_name} not configured, skipping."
261
256
  next
262
257
  end
263
258
 
264
- branch = repo['branch']
265
- files = repo['files']
266
-
267
259
  repo_dir = File.join(repos_path, repo_name)
268
260
  unless File.exist?(repo_dir)
269
- puts "[ERROR] #{repo_name} is missing in #{repos_path}, skipping pull for it."
261
+ puts(
262
+ "[ERROR] #{repo_name} is missing in #{repos_path}, " \
263
+ " skipping pull for it."
264
+ )
265
+
270
266
  next
271
267
  end
272
268
 
@@ -274,10 +270,9 @@ module Cimas
274
270
 
275
271
  dry_run("Pulling from #{repo_name}...") do
276
272
  puts "Pulling from #{repo_name}..."
277
- g.reset_hard(branch)
278
- g.checkout(branch)
273
+ g.reset_hard(repo.branch)
274
+ g.checkout(repo.branch)
279
275
  g.pull
280
- # g.fetch(g.remotes.first)
281
276
  end
282
277
  end
283
278
 
@@ -322,6 +317,7 @@ module Cimas
322
317
 
323
318
  filtered_repo_names.each do |repo_name|
324
319
  repo = repo_by_name(repo_name)
320
+
325
321
  if repo.nil?
326
322
  puts "[WARNING] #{repo_name} not configured, skipping."
327
323
  next
@@ -334,11 +330,13 @@ module Cimas
334
330
  end
335
331
 
336
332
  g = Git.open(repo_dir)
337
- # g.reset_hard(attribs['branch'])
338
-
339
333
  dry_run("Pushing branch #{push_to_branch} (commit #{g.object('HEAD').sha}) to #{g.remotes.first}:#{repo_name}") do
340
- g.branch(push_to_branch).checkout
334
+ puts "repo.branch #{repo.branch}"
335
+ g.checkout(repo.branch)
336
+ g.reset(repo.branch)
337
+ g.branch(push_to_branch).delete
341
338
  g.add(all: true)
339
+ g.branch(push_to_branch).checkout
342
340
 
343
341
  if g.status.changed.empty? &&
344
342
  g.status.added.empty? &&
@@ -346,7 +344,8 @@ module Cimas
346
344
 
347
345
  puts "Skipping commit on #{repo_name}, no changes detected."
348
346
  else
349
- g.commit_all(commit_message)
347
+ puts "Committing on #{repo_name}."
348
+ g.commit_all(commit_message)#, amend: true)
350
349
  end
351
350
 
352
351
  # Still push even if there was no commit, as the remote branch
@@ -354,10 +353,10 @@ module Cimas
354
353
  # make PRs in the next stage.
355
354
 
356
355
  if force_push
357
- # TODO implement
358
- raise "[ERROR] Force pushing with commit amend is not yet implemented."
356
+ puts "Force-pushing branch #{push_to_branch} (commit #{g.object('HEAD').sha}) to #{g.remotes.first}:#{repo_name}."
357
+ g.push(g.remotes.first, push_to_branch, force: true)
359
358
  else
360
- puts "Pushing branch #{push_to_branch} (commit #{g.object('HEAD').sha}) to #{g.remotes.first}:#{repo_name}"
359
+ puts "Pushing branch #{push_to_branch} (commit #{g.object('HEAD').sha}) to #{g.remotes.first}:#{repo_name}."
361
360
  g.push(g.remotes.first, push_to_branch)
362
361
  end
363
362
  end
@@ -393,15 +392,15 @@ module Cimas
393
392
  end
394
393
 
395
394
  g = Git.open(repo_dir)
396
- github_slug = git_remote_to_github_name(repo['remote'])
395
+ github_slug = git_remote_to_github_name(repo.remote)
397
396
 
398
- dry_run("Opening GitHub PR: #{github_slug}, branch #{repo['branch']} <- #{branch}, message '#{message}'") do
399
- puts "Opening GitHub PR: #{github_slug}, branch #{repo['branch']} <- #{branch}, message '#{message}'"
397
+ dry_run("Opening GitHub PR: #{github_slug}, branch #{repo.branch} <- #{branch}, message '#{message}'") do
398
+ puts "Opening GitHub PR: #{github_slug}, branch #{repo.branch} <- #{branch}, message '#{message}'"
400
399
 
401
400
  begin
402
401
  pr = github_client.create_pull_request(
403
402
  github_slug,
404
- repo['branch'],
403
+ repo.branch,
405
404
  branch,
406
405
  message,
407
406
  "As title. \n\n _Generated by Cimas_."
@@ -421,6 +420,11 @@ module Cimas
421
420
  when /field: head\s+code: invalid/
422
421
  puts "[WARNING] Branch #{branch} does not exist on #{github_slug}. Did you run `push`? Skipping."
423
422
  next
423
+
424
+ when /message: No commits between/
425
+ puts "[WARNING] Target branch (#{repo.branch}) is on par with new branch (#{branch}). Skipping."
426
+ next
427
+
424
428
  else
425
429
  raise e
426
430
  end
@@ -0,0 +1,25 @@
1
+ module Cimas
2
+ class Repository
3
+ attr_reader :name, :remote, :branch, :files
4
+
5
+ def initialize(name, attributes = {})
6
+ init_from_attributes(name, attributes)
7
+ end
8
+
9
+ def nil?
10
+ remote == nil && branch == nil
11
+ end
12
+
13
+ private
14
+
15
+ def init_from_attributes(name, attributes)
16
+ if attributes
17
+ @name = name
18
+
19
+ @remote = attributes.fetch("remote", nil)
20
+ @branch = attributes.fetch("branch", nil)
21
+ @files = attributes.fetch("files", nil)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Cimas
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cimas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-13 00:00:00.000000000 Z
11
+ date: 2020-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: travis
@@ -110,11 +110,13 @@ files:
110
110
  - README.adoc
111
111
  - Rakefile
112
112
  - bin/console
113
+ - bin/rspec
113
114
  - bin/setup
114
115
  - cimas.gemspec
115
116
  - exe/cimas
116
117
  - lib/cimas.rb
117
118
  - lib/cimas/cli/command.rb
119
+ - lib/cimas/repository.rb
118
120
  - lib/cimas/version.rb
119
121
  homepage: https://github.com/metanorma/cimas
120
122
  licenses: