Skip to content

Commit

Permalink
Merge branch 'upstream-0.25.0' into orange-main
Browse files Browse the repository at this point in the history
  • Loading branch information
o-orand committed May 13, 2024
2 parents f1de1ac + 556f25f commit 2f74a8d
Show file tree
Hide file tree
Showing 18 changed files with 222 additions and 197 deletions.
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# Binaries
build/*

# Taskfile
.task

# Task installation in Travis
bin/task

# Editor
.idea/
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Default. Unless we have a more specific match.
* @telia-oss/golang
* @gstackio/staff
29 changes: 21 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
FROM golang:1.21.6 AS builder
ARG golang="golang:1.21.6"
ARG alpine="alpine:3.19.1"


FROM ${golang} AS builder

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get -y -qq update \
&& apt-get -y -qq install "make"

ADD . /go/src/github.com/telia-oss/github-pr-resource
WORKDIR /go/src/github.com/telia-oss/github-pr-resource
RUN curl -sL https://taskfile.dev/install.sh | sh /dev/stdin v3.33.1
RUN ./bin/task build

FROM alpine:3.19.1 AS resource
COPY --from=builder /go/src/github.com/telia-oss/github-pr-resource/build /opt/resource
RUN go version \
&& make all


FROM ${alpine} AS resource
RUN apk add --update --no-cache \
git \
git-lfs \
openssh \
git-crypt \
&& chmod +x /opt/resource/*
git-crypt
COPY scripts/askpass.sh /usr/local/bin/askpass.sh
COPY --from=builder /go/src/github.com/telia-oss/github-pr-resource/build /opt/resource
RUN chmod +x /opt/resource/*



FROM resource
LABEL MAINTAINER=telia-oss
LABEL MAINTAINER=orange-cloudfoundry
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ e2e: test
go test -race -v ./... -tags=e2e

check: cmd/check/main.go
CGO_ENABLED=0 \
go build -o "build/check" -ldflags="-s -w" -v "cmd/check/main.go"

in: cmd/in/main.go
CGO_ENABLED=0 \
go build -o "build/in" -ldflags="-s -w" -v "cmd/in/main.go"

out: cmd/out/main.go
CGO_ENABLED=0 \
go build -o "build/out" -ldflags="-s -w" -v "cmd/out/main.go"
44 changes: 37 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ Inspired by [the original][original-resource], with some important differences:

Make sure to check out [#migrating](#migrating) to learn more.


### Maintainance notice

This project is a fork of [telia-oss/github-pr-resource][telia_repo], which
hasn't received any maintenance for years, as telia-oss/github-pr-resource#246
can testify and explain.

As exmplained in [this comment][maintainance_takeover_comment], the project
here is to take over the maintenance, merge [pending contributions][pending_contributions]
that have been submitted as PRs to the original repo and bring significant
features, and at some point build a solution for a growing code base of
automated tests.

[telia_repo]: https://github.com/telia-oss/github-pr-resource
[maintainance_takeover_comment]: https://github.com/telia-oss/github-pr-resource/issues/246#issuecomment-2105230468
[pending_contributions]: https://github.com/telia-oss/github-pr-resource/pulls


## Source Configuration

| Parameter | Required | Example | Description |
Expand Down Expand Up @@ -84,8 +102,16 @@ input. Because the base of the PR is not locked to a specific commit in versions
requested version and the metadata emitted by `get` are available to your tasks as JSON:
- `.git/resource/version.json`
- `.git/resource/metadata.json`
- `.git/resource/metadata-map.json`
- `.git/resource/changed_files` (if enabled by `list_changed_files`)

The `metadata.json` file contains an array of objects, one for each key-value
pair, with a `name` key and a `value` key. In order to support the
[`load_var` step][load_var_step], another `metadata-map.json` provides the
same informtion with a plain key-value format.

[load_var_step]: https://concourse-ci.org/load-var-step.html

The information in `metadata.json` is also available as individual files in the `.git/resource` directory, e.g. the `base_sha`
is available as `.git/resource/base_sha`. For a complete list of available (individual) metadata files, please check the code
[here](https://github.com/telia-oss/github-pr-resource/blob/master/in.go#L66).
Expand All @@ -94,6 +120,7 @@ is available as `.git/resource/base_sha`. For a complete list of available (indi
- `author_email`: the e-mail address of the pull request author
- `base_name`: the base branch of the pull request
- `base_sha`: the commit of the base branch of the pull request
- `body`: the description of the pull request
- `head_name`: the branch associated with the pull request
- `head_sha`: the latest commit hash of the branch associated with the pull request
- `message`: the message of the last commit of the pull request, as designated by `head_sha`
Expand Down Expand Up @@ -265,13 +292,16 @@ If you are coming from [jtarchie/github-pullrequest-resource][original-resource]
#### Metadata stored in the `.git` directory

The original resource stores [a bunch of metadata][metadata] related to the
pull request as `git config`, or plain files in the `.git` directory. This
resource provide most metadata with possibly different names, and the files
are to be found in the `.git/reource` directory.
pull request as entries in `.git/config`, or plain files in the `.git/`
directory.

This resource provide all these metadata, but with possibly different names,
and only as files to be found in the `.git/resource` directory.

If you were using the metadata stored in Git config, you need to update your
code. For example `git config --get pullrequest.url` in some Bash code can be
replaced by `echo $(< .git/resource/url)`.
With this resource, no entry is added to the `.git/config` file. If you were
using the metadata stored in Git config, you need to update your code. For
example `git config --get pullrequest.url` in some Bash code can be replaced
by `echo $(< .git/resource/url)`.

Here is the list of changes:

Expand All @@ -282,7 +312,7 @@ Here is the list of changes:
- `.git/branch` -> `.git/resource/head_name`
- `.git/head_sha` -> `.git/resource/head_sha`
- `.git/userlogin` -> `.git/resource/author`
- `.git/body` -> _no equivalent_
- `.git/body` -> `.git/resource/body`

[metadata]: https://github.com/jtarchie/github-pullrequest-resource#in-clone-the-repository-at-the-given-pull-request-ref

Expand Down
66 changes: 0 additions & 66 deletions Taskfile.yml

This file was deleted.

10 changes: 8 additions & 2 deletions ci/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ meta:
fail_moji: ":airplane_arriving:"
upset_moji: ":sadpanda:"
pipeline_url: (( concat meta.url "/teams/${BUILD_TEAM_NAME}/pipelines/${BUILD_PIPELINE_NAME}" ))
fail_link: (( concat "<" meta.slack.pipeline_url "/jobs/${BUILD_JOB_NAME}/builds/${BUILD_NAME}| Concourse Failure! " meta.slack.upset_moji ">" ))
fail_text: '(( concat meta.slack.fail_link " " meta.pipeline ": `${BUILD_JOB_NAME}` job failed" ))'
fail_link: (( concat "<" meta.slack.pipeline_url "/jobs/${BUILD_JOB_NAME}/builds/${BUILD_NAME}| Let's go fix it!>" ))
fail_text: '(( concat meta.pipeline ": `${BUILD_JOB_NAME}` job has failed " meta.slack.upset_moji " " meta.slack.fail_link " :hammer_and_wrench:" ))'

groups:
- name: (( grab meta.name ))
Expand Down Expand Up @@ -102,6 +102,7 @@ jobs:

on_failure:
put: notify
no_get: true
params:
channel: (( grab meta.slack.channel ))
username: (( grab meta.slack.username ))
Expand Down Expand Up @@ -170,6 +171,7 @@ jobs:

on_success:
put: notify
no_get: true
params:
channel: (( grab meta.slack.channel ))
username: (( grab meta.slack.username ))
Expand Down Expand Up @@ -213,6 +215,7 @@ jobs:
params: { file: version/number }
on_failure:
put: notify
no_get: true
params:
channel: (( grab meta.slack.channel ))
username: (( grab meta.slack.username ))
Expand All @@ -227,6 +230,7 @@ jobs:
- { put: version, params: { file: version/number } }
on_failure:
put: notify
no_get: true
params:
channel: (( grab meta.slack.channel ))
username: (( grab meta.slack.username ))
Expand All @@ -241,6 +245,7 @@ jobs:
- { put: version, params: { file: version/number } }
on_failure:
put: notify
no_get: true
params:
channel: (( grab meta.slack.channel ))
username: (( grab meta.slack.username ))
Expand Down Expand Up @@ -317,6 +322,7 @@ jobs:
body: gh/notes.md
on_failure:
put: notify
no_get: true
params:
channel: (( grab meta.slack.channel ))
username: (( grab meta.slack.username ))
Expand Down
4 changes: 0 additions & 4 deletions ci/release_notes.md

This file was deleted.

21 changes: 14 additions & 7 deletions ci/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,22 @@ jobs:
| xargs -0 -I{} cp -a {} "repo-bumped"
cd "repo-bumped" || exit 115
awk '/^go /{print $2}' go.mod > ../golang-info/previous-version
awk '/^toolchain /{sub(/go/,"",$2); print $2}' go.mod \
> ../golang-info/previous-version
(
set -x
go_version=$(
go version \
| awk '{sub(/go/,"",$3); sub(/\.[[:digit:]]+$/,"",$3); print $3}'
)
sed -i -Ee "s/^go [[:digit:].]+\$/go ${go_version}/" go.mod
toolchain_version=$(go version | awk '{print $3}')
go_version=${toolchain_version#"go"}
inferred_go_min_version="${go_version%.*}.0"
sed -i -Ee "s/^go [[:digit:].]+\$/go ${inferred_go_min_version}/" go.mod
sed -i -Ee "s/^toolchain go[[:digit:].]+\$/toolchain ${toolchain_version}/" go.mod
go get -t -u ./...
go mod tidy
echo "${go_version}" > ../golang-info/version
echo "${toolchain_version}" > ../golang-info/toolchain-version
echo "${go_version}" > ../golang-info/version
echo "${inferred_go_min_version}" > ../golang-info/min-version
)
- task: build-docker-image
Expand All @@ -188,6 +192,7 @@ jobs:
caches: [ path: cache ]
run: { path: build }
params:
DEBUG: true
IMAGE_ARG_golang: golang-latest/image.tar
IMAGE_ARG_alpine: alpine-latest/image.tar
output_mapping:
Expand Down Expand Up @@ -245,13 +250,15 @@ jobs:

on_failure:
put: notify
no_get: true
params:
channel: (( grab meta.slack.channel ))
username: (( grab meta.slack.username ))
icon_url: (( grab meta.slack.icon ))
text: (( grab meta.slack.fail_text ))
on_success:
put: notify
no_get: true
params:
channel: (( grab meta.slack.channel ))
username: (( grab meta.slack.username ))
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

resource "github.com/telia-oss/github-pr-resource"

"github.com/google/go-github/v42/github"
"github.com/google/go-github/v61/github"
"github.com/shurcooL/githubv4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
11 changes: 9 additions & 2 deletions github.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strconv"
"strings"

"github.com/google/go-github/v58/github"
"github.com/google/go-github/v61/github"
"github.com/shurcooL/githubv4"
"golang.org/x/oauth2"
)
Expand Down Expand Up @@ -435,7 +435,7 @@ func (m *GithubClient) DeletePreviousComments(prNumber string) error {
}

for _, e := range getComments.Repository.PullRequest.Comments.Edges {
if e.Node.Author.Login == getComments.Viewer.Login {
if cleanBotUserName(e.Node.Author.Login) == cleanBotUserName(getComments.Viewer.Login) {
_, err := m.V3.Issues.DeleteComment(context.TODO(), m.Owner, m.Repository, e.Node.DatabaseId)
if err != nil {
return err
Expand All @@ -453,3 +453,10 @@ func parseRepository(s string) (string, string, error) {
}
return parts[0], parts[1], nil
}

func cleanBotUserName(username string) string {
if strings.HasSuffix(username, "[bot]") {
return strings.TrimSuffix(username, "[bot]")
}
return username
}
Loading

0 comments on commit 2f74a8d

Please sign in to comment.