You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2023/07/10 12:15:24 UTC

[camel-k] 02/02: feat: added workflow to handle comment on pr

This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit f6f18e4081f263328fc609828ab26d1f9b550725
Author: Martin Olsiak <ma...@gmail.com>
AuthorDate: Mon Jul 10 13:34:15 2023 +0200

    feat: added workflow to handle comment on pr
---
 .github/workflows/coverage-report-comment.yml | 86 +++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)

diff --git a/.github/workflows/coverage-report-comment.yml b/.github/workflows/coverage-report-comment.yml
new file mode 100644
index 000000000..a9c42d792
--- /dev/null
+++ b/.github/workflows/coverage-report-comment.yml
@@ -0,0 +1,86 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License. 
+# ---------------------------------------------------------------------------
+
+name: coverage-report-comment
+
+on:
+  workflow_run:
+    workflows: ["coverage-report"]
+    types:
+      - completed
+
+jobs:
+  comment:
+    runs-on: ubuntu-latest
+    if : ${{ github.event.workflow_run.conclusion == 'success' }}
+    steps:
+      - name: 'Download artifact'
+        uses: actions/github-script@v3.1.0
+        with:
+          script: |
+            var artifacts = await github.actions.listWorkflowRunArtifacts({
+               owner: context.repo.owner,
+               repo: context.repo.repo,
+               run_id: ${{github.event.workflow_run.id }},
+            });
+            var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
+              return artifact.name == "pr"
+            })[0];
+            var download = await github.actions.downloadArtifact({
+               owner: context.repo.owner,
+               repo: context.repo.repo,
+               artifact_id: matchArtifact.id,
+               archive_format: 'zip',
+            });
+            var fs = require('fs');
+            fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
+      - run: unzip pr.zip
+
+      - name: Comment Coverage
+        uses: actions/github-script@v6
+        with:
+          github-token: ${{secrets.GITHUB_TOKEN}}
+          script: |
+            var fs = require('fs');
+            var issue_number = Number(fs.readFileSync('./NR'));
+            var POS_DIFF = Number(fs.readFileSync('./POS_DIFF'));
+            var OLD_COV = Number(fs.readFileSync('./OLD_COV'));
+            var NEW_COV = Number(fs.readFileSync('./NEW_COV'));
+            var COV_DIFF = Number(fs.readFileSync('./COV_DIFF'));
+
+            if( POS_DIFF  == 'POS'){
+              github.rest.issues.createComment({
+                issue_number: issue_number,
+                owner: context.repo.owner,
+                repo: context.repo.repo,
+                body: `:camel: **Thank you for contributing!** :camel: \n\n  **Code Coverage Report** :heavy_check_mark:\n - Coverage changed from: **${OLD_COV}%** -> **${NEW_COV}%**\n- Coverage difference: +**${COV_DIFF}%**`
+              })
+            }else if(POS_DIFF == 'NEG'){
+              github.rest.issues.createComment({
+              issue_number: issue_number,
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              body: `:camel: **Thank you for contributing!** :camel: \n\n  **Code Coverage Report** :warning:\n - Coverage changed from: **${OLD_COV}%** -> **${NEW_COV}%**\n- Coverage difference: **${COV_DIFF}%**`
+              })
+            }else{
+              github.rest.issues.createComment({
+              issue_number: issue_number,
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              body: `:camel: **Thank you for contributing!** :camel: \n\n  **Code Coverage Report** :heavy_check_mark:\n - Coverage unchanged.`
+              })
+            }
\ No newline at end of file