Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatize Branch Creation from Github Issue #125

Open
trinitytakei opened this issue Nov 24, 2024 · 1 comment
Open

Automatize Branch Creation from Github Issue #125

trinitytakei opened this issue Nov 24, 2024 · 1 comment

Comments

@trinitytakei
Copy link
Member

Something like this script for Pivotal Tracker:

#!/usr/bin/env ruby
require 'json'

if ENV['PT_TOKEN'].nil?
  puts <<~PT_TOKEN_NOT_PROVIDED
    ERROR: PT_TOKEN env variable not set, exiting...

    Please go to your profile page: https://www.pivotaltracker.com/profile
    You should see the API token near the bottom
    set up an environment variable called PT_TOKEN with your API key as the value, i.e.

    export PT_TOKEN=myt0k3nh3r3

    even better, use something like .evnrc + direnv
  PT_TOKEN_NOT_PROVIDED
end


if ARGV[0].nil?
  puts <<~ID_NOT_PROVIDED
    ERROR: ticket ID not provided, exiting...

    Please proveide a ticket ID, ie something like

    bin/story 12345 # or whatever the ticket number is
  ID_NOT_PROVIDED

  exit
end

ticket_id = ARGV[0].
  gsub('#','')

puts "Grabbing ticket ID #{ticket_id}"

`curl -X GET -H "X-TrackerToken: $PT_TOKEN" "https://www.pivotaltracker.com/services/v5/stories/#{ARGV[0]}"`
  .then { |raw_response|         JSON.parse(raw_response) }
  .then { |json_response|        fail "ERROR: #{json_response}" if json_response["error"]; json_response }
  .then { |json_response|        branch_name, ticket_id = json_response.values_at("id", "name") }
  .then { |ticket_data|          ticket_data.join(' ') }
  .then { |ticket_string_spaces| ticket_string_spaces.tr(' ', '-').chomp('.') } #TODO - where's . coming from? >.<
  .then { |branch_name|          puts "creating new branch: >>#{branch_name}<<"; branch_name }
  .then { |branch_name|          `git checkout -b #{branch_name}` }
Copy link

linear bot commented Nov 24, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant