From 96e35db18ec14a5e13927ae37e701eca0d41adfc Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 5 Mar 2022 17:10:25 +0300 Subject: [PATCH 1/6] add message metadata support Signed-off-by: Vasiliy Tolstov --- http.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/http.go b/http.go index 8e843df..b29468a 100644 --- a/http.go +++ b/http.go @@ -604,6 +604,8 @@ func (h *httpClient) Publish(ctx context.Context, p client.Message, opts ...clie } func (h *httpClient) publish(ctx context.Context, ps []client.Message, opts ...client.PublishOption) error { + var body []byte + options := client.NewPublishOptions(opts...) // get proxy @@ -622,24 +624,22 @@ func (h *httpClient) publish(ctx context.Context, ps []client.Message, opts ...c for _, p := range ps { md := metadata.Copy(omd) md[metadata.HeaderContentType] = p.ContentType() - md[metadata.HeaderTopic] = p.Topic() - - cf, err := h.newCodec(p.ContentType()) - if err != nil { - return errors.InternalServerError("go.micro.client", err.Error()) - } - - var body []byte // passed in raw data if d, ok := p.Payload().(*codec.Frame); ok { body = d.Data } else { - b := bytes.NewBuffer(nil) - if err := cf.Write(b, &codec.Message{Type: codec.Event}, p.Payload()); err != nil { + // use codec for payload + cf, err := h.newCodec(p.ContentType()) + if err != nil { return errors.InternalServerError("go.micro.client", err.Error()) } - body = b.Bytes() + // set the body + b, err := cf.Marshal(p.Payload()) + if err != nil { + return errors.InternalServerError("go.micro.client", err.Error()) + } + body = b } topic := p.Topic() @@ -647,6 +647,9 @@ func (h *httpClient) publish(ctx context.Context, ps []client.Message, opts ...c topic = exchange } + for k, v := range p.Metadata() { + md.Set(k, v) + } md.Set(metadata.HeaderTopic, topic) msgs = append(msgs, &broker.Message{Header: md, Body: body}) } -- 2.47.1 From 631dd92385d536cd2a9ed523ffdd0e62d0db224b Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 5 Mar 2022 17:14:18 +0300 Subject: [PATCH 2/6] fix workflow Signed-off-by: Vasiliy Tolstov --- .github/workflows/dependabot-automerge.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependabot-automerge.yml b/.github/workflows/dependabot-automerge.yml index 12490d1..8190317 100644 --- a/.github/workflows/dependabot-automerge.yml +++ b/.github/workflows/dependabot-automerge.yml @@ -11,7 +11,7 @@ permissions: jobs: dependabot: runs-on: ubuntu-latest - if: ${{ github.actor == 'dependabot[bot]' }} + if: ${{ github.actor == 'dependabot[bot]' || github.actor == 'vtolstov' }} steps: - name: metadata id: metadata -- 2.47.1 From 6c7342b9aa2f3935c76d48d8aeb1d4eb43229129 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 5 Mar 2022 17:16:28 +0300 Subject: [PATCH 3/6] fix workflow Signed-off-by: Vasiliy Tolstov --- .github/workflows/autoreview.yml | 25 ++++++++++++++++++++++ .github/workflows/dependabot-automerge.yml | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/autoreview.yml diff --git a/.github/workflows/autoreview.yml b/.github/workflows/autoreview.yml new file mode 100644 index 0000000..69e9d5b --- /dev/null +++ b/.github/workflows/autoreview.yml @@ -0,0 +1,25 @@ +name: "prautomerge" + +on: + pull_request_target: + types: [assigned, opened, synchronize, reopened] + +permissions: + pull-requests: write + contents: write + +jobs: + dependabot: + runs-on: ubuntu-latest + if: ${{ github.actor == 'vtolstov' }} + steps: + - name: metadata + id: metadata + uses: dependabot/fetch-metadata@v1.3.0 + with: + github-token: "${{ secrets.TOKEN }}" + - name: approve + run: gh pr review --approve "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.TOKEN}} diff --git a/.github/workflows/dependabot-automerge.yml b/.github/workflows/dependabot-automerge.yml index 8190317..f1f7774 100644 --- a/.github/workflows/dependabot-automerge.yml +++ b/.github/workflows/dependabot-automerge.yml @@ -11,7 +11,7 @@ permissions: jobs: dependabot: runs-on: ubuntu-latest - if: ${{ github.actor == 'dependabot[bot]' || github.actor == 'vtolstov' }} + if: ${{ github.actor == 'dependabot[bot]'}} steps: - name: metadata id: metadata -- 2.47.1 From fe8f07a2fc6ac9b0ba74fc709eccf76678b54c13 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 5 Mar 2022 17:17:02 +0300 Subject: [PATCH 4/6] fix workflow Signed-off-by: Vasiliy Tolstov --- .github/workflows/autoreview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/autoreview.yml b/.github/workflows/autoreview.yml index 69e9d5b..823aec0 100644 --- a/.github/workflows/autoreview.yml +++ b/.github/workflows/autoreview.yml @@ -1,4 +1,4 @@ -name: "prautomerge" +name: "autoreview" on: pull_request_target: -- 2.47.1 From b8a733753144f208576ab3e63d81b7fb2572bf60 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 5 Mar 2022 17:22:56 +0300 Subject: [PATCH 5/6] fix workflow Signed-off-by: Vasiliy Tolstov --- .../workflows/{dependabot-automerge.yml => automerge.yml} | 8 ++------ .github/workflows/autoreview.yml | 4 +++- 2 files changed, 5 insertions(+), 7 deletions(-) rename .github/workflows/{dependabot-automerge.yml => automerge.yml} (73%) diff --git a/.github/workflows/dependabot-automerge.yml b/.github/workflows/automerge.yml similarity index 73% rename from .github/workflows/dependabot-automerge.yml rename to .github/workflows/automerge.yml index f1f7774..64e1b7c 100644 --- a/.github/workflows/dependabot-automerge.yml +++ b/.github/workflows/automerge.yml @@ -11,18 +11,14 @@ permissions: jobs: dependabot: runs-on: ubuntu-latest - if: ${{ github.actor == 'dependabot[bot]'}} + if: | + github.actor == 'dependabot[bot]' steps: - name: metadata id: metadata uses: dependabot/fetch-metadata@v1.3.0 with: github-token: "${{ secrets.TOKEN }}" - - name: approve - run: gh pr review --approve "$PR_URL" - env: - PR_URL: ${{github.event.pull_request.html_url}} - GITHUB_TOKEN: ${{secrets.TOKEN}} - name: merge if: ${{contains(steps.metadata.outputs.dependency-names, 'go.unistack.org')}} run: gh pr merge --auto --merge "$PR_URL" diff --git a/.github/workflows/autoreview.yml b/.github/workflows/autoreview.yml index 823aec0..2b95906 100644 --- a/.github/workflows/autoreview.yml +++ b/.github/workflows/autoreview.yml @@ -11,7 +11,9 @@ permissions: jobs: dependabot: runs-on: ubuntu-latest - if: ${{ github.actor == 'vtolstov' }} + if: | + github.actor == 'vtolstov' || + github.actor == 'dependabot[bot]' steps: - name: metadata id: metadata -- 2.47.1 From fb03cf691ee16095221ffaf907420f94dc9bd4d6 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 5 Mar 2022 18:23:49 +0300 Subject: [PATCH 6/6] change workflow Signed-off-by: Vasiliy Tolstov --- .github/workflows/autoreview.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/autoreview.yml b/.github/workflows/autoreview.yml index 2b95906..071176d 100644 --- a/.github/workflows/autoreview.yml +++ b/.github/workflows/autoreview.yml @@ -15,11 +15,6 @@ jobs: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]' steps: - - name: metadata - id: metadata - uses: dependabot/fetch-metadata@v1.3.0 - with: - github-token: "${{ secrets.TOKEN }}" - name: approve run: gh pr review --approve "$PR_URL" env: -- 2.47.1