Skip to content

Commit

Permalink
fix: Remove Git fields in Api graphiql
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentinchampenois committed Nov 26, 2023
1 parent 8965d5e commit fc55da5
Showing 1 changed file with 2 additions and 50 deletions.
52 changes: 2 additions & 50 deletions app/api/deployment_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,9 @@
class DeploymentType < Decidim::Api::Types::BaseObject
description "Deployment's related properties."

field :current_commit, GraphQL::Types::String, "The current commit hash for this deployment", null: false
field :branch, GraphQL::Types::String, "The current branch name for this deployment", null: false
field :remote, GraphQL::Types::String, "The current remote for this deployment", null: false
field :version, GraphQL::Types::String, "The current decidim's version of this deployment.", null: false
field :up_to_date, GraphQL::Types::Boolean, "Comparison between current_commit and latest_commit", null: false
field :latest_commit, GraphQL::Types::String, "Latest commit on the remote branch", null: false
field :locally_modified, GraphQL::Types::Boolean, "Output of git status", null: false
field :decidim_version, GraphQL::Types::String, "The Decidim version", null: false

def current_commit
`git rev-parse HEAD`.strip
end

def remote
`git ls-remote --get-url`.strip
end

def version
def decidim_version
Decidim.version
end

def branch
`git rev-parse --abbrev-ref HEAD`.strip
end

def up_to_date
current_commit == latest_commit
end

def latest_commit
url = URI("https://api.github.com/repos/#{partial_url}/commits/#{branch}")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Get.new(url)

response = https.request(request)
if response.code == "200"
JSON.parse(response.read_body)["sha"]
else
""
end
end

def locally_modified
!`git status --porcelain`.strip.empty?
end

def partial_url
remote = `git ls-remote --get-url`.strip
remote.sub(%r{https://github.com/}, "")
.sub(/(.git)(?!.*\1)/, "")
end
end

0 comments on commit fc55da5

Please sign in to comment.