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

Debugging fork #1

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ WORKDIR /go/src/github.com/cloudfoundry-community/github-pr-instances-resource
RUN curl -sL https://taskfile.dev/install.sh | sh
RUN ./bin/task build

FROM ${base_image} as resource

FROM ruby:3-alpine as resource
RUN apk add --update --no-cache \
git \
git-lfs \
Expand All @@ -17,5 +17,10 @@ RUN apk add --update --no-cache \
COPY scripts/askpass.sh /usr/local/bin/askpass.sh

COPY --from=builder /go/src/github.com/cloudfoundry-community/github-pr-instances-resource/build /opt/resource
COPY check_cuckoo.rb /opt/resource/check
RUN chmod +x /opt/resource/*

RUN gem install octokit faraday-retry

FROM resource
LABEL MAINTAINER=samrees
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2'
version: '3'

vars:
BUILD_DIR: build
Expand Down
61 changes: 61 additions & 0 deletions check_cuckoo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env ruby

require 'octokit'
require 'json'

# this is a behavior switch to ease development and debugging
payload =
JSON.parse(
if File.exist? 'payload'
File.open('payload', 'r') {|f| f.read }
else
ARGF.read
end
)

unless payload.has_key? 'source'
STDERR.puts "Must pass 'source' on STDIN"
exit 1
end

required_values = ['access_token', 'repository', 'number']
required_values.each do |value|
unless payload['source'].has_key? value
STDERR.puts "Must set source.#{value} on STDIN"
exit 1
end
end

c = Octokit::Client.new(access_token: payload['source']['access_token'], per_page: 100)
c.auto_paginate = true

commits = c.pull_request_commits(payload['source']['repository'], payload['source']['number'])

# kinda hate concourse for this.
# concourse can pass us a version or not, that may not exist remotely.
# 1. if there are new commits, we return the commit we were passed and all new ones. cool. this is sane.
# 2. concourse passed us a version, but we cant find it. fck, user rewrote the remote commit log deleting everything. we return everything we have, lol to concourse's immutability
# 3. this is the first run, concourse has no knowledge of versions, we pass everything we have.
new_commits =
if payload['source'].has_key? 'version'
if index = commits.find_index{|e| e[:sha] == payload['source']['version']['sha'] }
commits[index..-1] # 1
else
commits[-1..] || [] # 2
end
else
commits[-1..] || [] # 3
end

# This *was* set to match this https://github.com/telia-oss/github-pr-resource
# Now its set to match this: https://github.com/cloudfoundry-community/github-pr-instances-resource
new_commits_cleaned =
new_commits.map do |e|
{
ref: e[:sha]
}
end

puts JSON.pretty_generate(new_commits_cleaned)

exit 0
6 changes: 3 additions & 3 deletions models/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ func (g *GitClient) Pull(uri, branch string, depth int, submodules bool, fetchTa
cmd := g.command("git", args...)

// Discard output to have zero chance of logging the access token.
cmd.Stdout = ioutil.Discard
cmd.Stderr = ioutil.Discard
// cmd.Stdout = ioutil.Discard
// cmd.Stderr = ioutil.Discard

if err := cmd.Run(); err != nil {
return fmt.Errorf("pull failed: %s", cmd)
return fmt.Errorf("pull failed: %s\nstdout: %s\n stderr: %s", cmd, cmd.Stdout, cmd.Stderr)
}
if submodules {
submodulesGet := g.command("git", "submodule", "update", "--init", "--recursive")
Expand Down
2 changes: 2 additions & 0 deletions payload
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"source":{"repository":"spothero/SpotHero-Django","pr_number":"8878","access_token":"ghp_<redacted>"}}