Skip to content

Use GH API to validate that git refs are accessible - #303

Merged
orta merged 3 commits into
masterfrom
api_validate
Apr 19, 2021
Merged

Use GH API to validate that git refs are accessible#303
orta merged 3 commits into
masterfrom
api_validate

Conversation

@orta

@orta orta commented Apr 19, 2021

Copy link
Copy Markdown
Member

/cc @justicz

@orta
orta merged commit f38c95d into master Apr 19, 2021
wrap_timeout { system('git', 'ls-remote', @specification.source[:git], ref.to_s) }

gh = GitHub.new(ENV['GH_REPO'], :username => ENV['GH_TOKEN'], :password => 'x-oauth-basic')
owner_name = url.split('github.com/')[1].split('/')[0]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing 2 splits will allow GitHub.com/foo/bar/baz to accidentally get through. I think you want to .split('/', 2) to avoid that

@specification.source[:commit] ||
@specification.source[:branch] ||
'HEAD'
wrap_timeout { system('git', 'ls-remote', @specification.source[:git], ref.to_s) }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could've kept this and just validated the two user supplied params didn't start with -


# Drop the optional .git reference in a url
repo_name = repo_name[0...-4] if repo_name.end_with? '.git'
req = gh.get("/repos/#{owner_name}/#{repo_name}/git/ref/#{ref}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also be wrapped in a timeout?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants