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

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

Merged
merged 3 commits into from Apr 19, 2021
Merged

Conversation

orta
Copy link
Member

@orta orta commented Apr 19, 2021

/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
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


ref = @specification.source[:tag] ||
@specification.source[:commit] ||
@specification.source[:branch] ||
'HEAD'
wrap_timeout { system('git', 'ls-remote', @specification.source[:git], ref.to_s) }
Copy link
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
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.

None yet

2 participants