makandra / geordi

Collection of command line tools used in our daily work with Ruby, Rails and Linux.
https://makandra.com/
MIT License
104 stars 16 forks source link

Add support for Linear.app for `commit`-command #218

Open brunosedler opened 3 months ago

brunosedler commented 3 months ago

In the future we will be using linear.app to manage stories and issues. Therefore geordi commit should be able to use linear issue titles to generate commit messages.

There is a ruby cli tool for the linear API: https://github.com/rubyists/linear-cli

makmic commented 3 months ago

Minimal implementation suggestion (no dependencies) given there is a global geordi setting linear_api_key and local linear_team_key:

Based on the graphql explorer https://studio.apollographql.com/public/Linear-API/variant/current/explorer

def my_issue_titles(linear_team_key)
  filter = {
    "team": {
      "key": {
        "eq": linear_team_key,
      }
    },
    "assignee": {
      "isMe": {
        "eq": true
      }
    },
    "state": {
      "type": {
        "eq": "started"
      }
    }
  }
  response = request_with_payload(<<~GRAPHQL, filter:)
    query Issues($filter: IssueFilter) {
      issues(filter: $filter) {
        nodes {
          title
        }
      }
    }
  GRAPHQL

  response.dig(*%w[data issues nodes])&.map {|node| node['title'] }
end

API_ENDPOINT = 'https://api.linear.app/graphql'.freeze

def request_with_payload(attributes, variables)
  def client
  response = HTTP
   .headers({
      'Content-Type' => 'application/json',
      'Authorization' => settings.linear_api_key
    })
   .post(API_ENDPOINT, json: { query: attributes.split.join(' '), variables: })
  @last_response = response
  parsed_response = JSON.parse(response.body)
  if parsed_response.key?('errors')
    raise parsed_response.dig('errors')
  else
    parsed_response['data']
  end
end

(I didn't test this particular code, ping me if you need further help)

makmic commented 3 months ago

Please update the card https://makandracards.com/makandra/54911-pretty-commit-messages-via-geordi after merging this issue

Also note that the filter

    "team": {
      "key": {
        "eq": linear_team_key,
      }
    },

should probably not do an "eq" comparison because multiple teams can be configured for the current project

makmic commented 2 weeks ago

Hi :wave: ,

could you give me some rough estimate or info on the implementation timeline for this (and its sibling) issue?

Thx!