You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

29 lines
870 B

  1. require "http/client"
  2. require "json"
  3. require "discordcr"
  4. struct MergeRequest
  5. JSON.mapping(
  6. title: String,
  7. web_url: String,
  8. iid: Int32,
  9. state: String,
  10. author: NamedTuple(username: String, web_url: String)
  11. )
  12. def formatify
  13. project = self.web_url.lchop("https://gitlab.com/").chomp("/merge_requests/#{self.iid}")
  14. output = "#{project}!#{self.iid} "
  15. output += "[@#{self.author[:username]}](#{self.author[:web_url]}): "
  16. output += "[#{self.title}](#{self.web_url}) "
  17. output += " **[\\✔]**" if self.state == "closed"
  18. output
  19. end
  20. end
  21. def get_mr(repo_id, issue_id)
  22. resp = HTTP::Client.get("https://gitlab.com/api/v4/projects/#{repo_id}/merge_requests/#{issue_id}", HTTP::Headers{"PRIVATE-TOKEN" => ENV["gl_token"]})
  23. raise "Negative API Response: #{resp.body}" unless resp.success?
  24. MergeRequest.from_json(resp.body)
  25. end