Commit 60922b0

mo khan <mo@mokhan.ca>
2021-02-27 23:21:45
Add command to edit pr description
1 parent 2f6a51d
lib/jive/templates/pull_request_template.md
@@ -0,0 +1,41 @@
+# Pull Request Template
+
+## Description
+
+Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
+
+Fixes # (issue)
+
+## Type of change
+
+Please delete options that are not relevant.
+
+- [ ] Bug fix (non-breaking change which fixes an issue)
+- [ ] New feature (non-breaking change which adds functionality)
+- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
+- [ ] This change requires a documentation update
+
+## How Has This Been Tested?
+
+Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
+
+- [ ] Test A
+- [ ] Test B
+
+**Test Configuration**:
+* Firmware version:
+* Hardware:
+* Toolchain:
+* SDK:
+
+## Checklist:
+
+- [ ] My code follows the style guidelines of this project
+- [ ] I have performed a self-review of my own code
+- [ ] I have commented my code, particularly in hard-to-understand areas
+- [ ] I have made corresponding changes to the documentation
+- [ ] My changes generate no new warnings
+- [ ] I have added tests that prove my fix is effective or that my feature works
+- [ ] New and existing unit tests pass locally with my changes
+- [ ] Any dependent changes have been merged and published in downstream modules
+- [ ] I have checked my code and corrected any misspellings
lib/jive/cli.rb
@@ -74,6 +74,12 @@ module Jive
           .bootstrap(Jive.shell)
       end
 
+      desc "pr URL", "pull request"
+      def pr(url)
+        pr = PullRequest.new(url)
+        pr.edit(ENV["EDITOR"])
+      end
+
       desc "setup", "provide instructions to integrate into shell"
       def setup
         print "source #{::Jive.root.join("jive.sh")}"
lib/jive/pull_request.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+module Jive
+  class PullRequest
+    attr_reader :dir, :uri
+
+    def initialize(url)
+      @uri = URI.parse(url)
+      @dir = Pathname(Dir.home).join(".jive").join(uri.host).join(uri.path[1..-1])
+      Jive.shell.execute([:mkdir, "-p", @dir]) unless @dir.exist?
+    end
+
+    def edit(editor)
+      Jive.shell.execute([editor, readme.to_s])
+    end
+
+    private
+
+    def template
+      Jive.root.join("lib/jive/templates/pull_request_template.md")
+    end
+
+    def readme
+      @readme ||=
+        begin
+          dir.join("README.md").tap do |readme|
+            readme.write(template.read) unless readme.exist?
+          end
+        end
+    end
+  end
+end
lib/jive.rb
@@ -8,6 +8,7 @@ require "jive/docker"
 require "jive/git"
 require "jive/popen"
 require "jive/project"
+require "jive/pull_request"
 require "jive/runner"
 require "jive/shell"
 require "jive/version"
Gemfile.lock
@@ -8,15 +8,15 @@ GEM
   remote: https://rubygems.org/
   specs:
     ast (2.4.2)
-    minitest (5.14.3)
+    minitest (5.14.4)
     parallel (1.20.1)
     parser (3.0.0.0)
       ast (~> 2.4.1)
     rainbow (3.0.0)
     rake (13.0.3)
-    regexp_parser (2.0.3)
+    regexp_parser (2.1.1)
     rexml (3.2.4)
-    rubocop (1.9.1)
+    rubocop (1.10.0)
       parallel (~> 1.10)
       parser (>= 3.0.0.0)
       rainbow (>= 2.2.2, < 4.0)
jive.gemspec
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
     "README.md",
     "jive.gemspec",
     "jive.sh"
-  ]
+  ] + Dir["lib/**/templates/*.md"]
   spec.bindir        = "exe"
   spec.executables   = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
   spec.require_paths = ["lib"]