Add tf-github-autoresponse job:
The job will response the new PR or issue on
the Github mirroring repos [1]
It uses Jenkins Generic Webhook Trigger plug-in
to catch the events when the PR/issue is created [2]
[1]: https://linaro.atlassian.net/browse/TFC-247
[2]: https://plugins.jenkins.io/generic-webhook-trigger/
Signed-off-by: Arthur She <arthur.she@linaro.org>
Change-Id: I53a61349ef20122030f27cd222b36535d2bf0e90
diff --git a/ci/TF-Hafnium_issue_comment.md b/ci/TF-Hafnium_issue_comment.md
new file mode 100644
index 0000000..2b59135
--- /dev/null
+++ b/ci/TF-Hafnium_issue_comment.md
@@ -0,0 +1,8 @@
+Hello @{user_name}!
+
+Thank you for raising an issue for *Hafnium*.
+
+Currently we're not actively monitoring the Github issue tracker. Please ping the community by dropping
+an email to our [public Hafnium mailing list](https://lists.trustedfirmware.org/mailman3/lists/hafnium.lists.trustedfirmware.org/).
+
+The *Hafnium* team
diff --git a/ci/TF-Hafnium_pr_comment.md b/ci/TF-Hafnium_pr_comment.md
new file mode 100644
index 0000000..df4857b
--- /dev/null
+++ b/ci/TF-Hafnium_pr_comment.md
@@ -0,0 +1,18 @@
+Hello @{user_name}!
+
+Thank you for your contribution to **Hafnium**!
+
+The Hafnium project is hosted by www.trustedfirmware.org. Our GitHub repo is accessible as a Read-Only mirror.
+
+## Looking for information about how to use the project?
+ To use [Hafnium Documentation](https://hafnium.readthedocs.io/en/latest/index.html) provide useful information about the implementation.
+The Getting Started Section documents all you need know to build Hafnium.
+
+## What if I face any problems?
+
+ * **Our mailing lists**
+ You can send us an email in the [public Hafnium mailing list](https://lists.trustedfirmware.org/mailman3/lists/hafnium.lists.trustedfirmware.org/). [Here](https://lists.trustedfirmware.org/mailman/listinfo) you can also find all the mailing lists for all the projects hosted under trustedfirmware.org.
+
+We are looking forward to seeing your patch submitted to trustedfirmware.org!
+
+The **Hafnium** team
diff --git a/ci/Trusted-Services_issue_comment.md b/ci/Trusted-Services_issue_comment.md
new file mode 100644
index 0000000..da99026
--- /dev/null
+++ b/ci/Trusted-Services_issue_comment.md
@@ -0,0 +1,15 @@
+Hello @{user_name}!
+
+
+Thank you for raising an issue for **Trusted Services**.
+
+To **raise a security issue** please follow the directions of the
+[Trusted Firmware Security Center](https://developer.trustedfirmware.org/w/collaboration/security_center/).
+
+Currently we're not actively monitoring the Github issue tracker. Please ping the community by dropping
+an email to our [public mailing list](https://lists.trustedfirmware.org/mailman3/lists/trusted-services.lists.trustedfirmware.org/).
+
+For more information about how to contribute please read the
+["Contributing"](https://trusted-services.readthedocs.io/en/latest/project/contributing.html) section of the documentation.
+
+The **Trusted Services** team
\ No newline at end of file
diff --git a/ci/Trusted-Services_pr_comment.md b/ci/Trusted-Services_pr_comment.md
new file mode 100644
index 0000000..2262866
--- /dev/null
+++ b/ci/Trusted-Services_pr_comment.md
@@ -0,0 +1,21 @@
+Hello @{user_name}!
+
+
+Thank you for your contribution to **Trusted Services**!
+
+This is a read only mirror. Please read the
+["Contributing"](https://trusted-services.readthedocs.io/en/latest/project/contributing.html)
+section of our documentation and resubmit your changes to the repository hosted in
+[gerrit](https://review.trustedfirmware.org/admin/repos/TS/trusted-services).
+Sorry for the inconveniences!
+
+You can find more information about the project on the
+[projects homepage](https://www.trustedfirmware.org/projects/trusted-services).
+
+## What if I face any problems?
+Please drop an email to our [public mailing list](https://lists.trustedfirmware.org/mailman3/lists/trusted-services.lists.trustedfirmware.org/).
+[Here](https://lists.trustedfirmware.org/mailman3/lists) you can also find all the mailing lists for all the projects hosted under trustedfirmware.org.
+
+We are looking forward to seeing your changes submitted!
+
+The **Trusted Services** team
diff --git a/ci/TrustedFirmware-A_issue_comment.md b/ci/TrustedFirmware-A_issue_comment.md
new file mode 100644
index 0000000..fb4d721
--- /dev/null
+++ b/ci/TrustedFirmware-A_issue_comment.md
@@ -0,0 +1,15 @@
+Hello @{user_name}!
+
+
+Thank you for raising an issue for **Trusted Firmware-A**.
+
+The TF-A project has now migrated to www.trustedfirmware.org. This issue tracker will still remain accessible for some time, but only for historical reasons. From now on you should raise new issues on trustedfirmware.org.
+
+If it is a query or a design discussion it is better discussed via the [mailing list](https://lists.trustedfirmware.org/mailman/listinfo/tf-a). If it is issue/bug which need to be tracked, raise an issue in the [issue tracking board](https://developer.trustedfirmware.org/maniphest/query/open/) and also send an email to the [mailing list](https://lists.trustedfirmware.org/mailman/listinfo/tf-a) to notify the TF-A community.
+
+## How do I raise issues for TF-A?
+Please use our new [issue tracking board](https://developer.trustedfirmware.org/maniphest/query/open/). For this you just need to login with your existing GitHub account. We also have a [guide](https://developer.trustedfirmware.org/dashboard/view/6/) to help you raise the issue with the appropriate labels and tags. This way it will be easier for both you and us to track and address the issue most effectively.
+
+We are looking forward to seeing you in trustedfirmware.org!
+
+The **Trusted Firmware-A** team
\ No newline at end of file
diff --git a/ci/TrustedFirmware-A_pr_comment.md b/ci/TrustedFirmware-A_pr_comment.md
new file mode 100644
index 0000000..0418224
--- /dev/null
+++ b/ci/TrustedFirmware-A_pr_comment.md
@@ -0,0 +1,24 @@
+Hello @{user_name}!
+
+
+Thank you for your contribution to **Trusted Firmware-A**!
+
+The TF-A project has now migrated to www.trustedfirmware.org. Our GitHub repo will remain accessible as a Read-Only mirror but we have changed the way we accept contributions for the project.
+
+## How do I contribute patches to TF-A?
+We have a [Getting started](https://developer.trustedfirmware.org/w/tf_a/gerrit-getting-started/) article which we hope will make everything very straightforward! And if you would like more details you can always refer to the [contributing guidelines](https://trustedfirmware-a.readthedocs.io/en/latest/process/contributing.html).
+
+A quick overview:
+1. Go to review.trustedfirmware.org
+2. Register with your existing GitHub account
+3. Submit your patches!
+
+## What if I face any problems?
+We have many channels through which you can contact us:
+
+ * **Our mailing lists**
+ You can send us an email in the [public TF-A mailing list](https://lists.trustedfirmware.org/mailman/listinfo/tf-a). [Here](https://lists.trustedfirmware.org/mailman/listinfo) you can also find all the mailing lists for all the projects hosted under trustedfirmware.org.
+
+We are looking forward to seeing your patch submitted to trustedfirmware.org!
+
+The **Trusted Firmware-A** team
diff --git a/ci/TrustedFirmware-M_issue_comment.md b/ci/TrustedFirmware-M_issue_comment.md
new file mode 100644
index 0000000..ed52119
--- /dev/null
+++ b/ci/TrustedFirmware-M_issue_comment.md
@@ -0,0 +1,9 @@
+Hello @{user_name}!
+Thank you for raising an issue for **Trusted-Firmware-M**.
+To **raise a security issue** please follow the directions of the
+[Trusted Firmware Security Center](https://developer.trustedfirmware.org/w/collaboration/security_center/).
+Currently we're not actively monitoring the Github issue tracker. Please ping the community by dropping
+an email to our [public mailing list](https://lists.trustedfirmware.org/mailman3/lists/tf-m.lists.trustedfirmware.org/).
+For more information about how to contribute please read the
+["Contributing"](https://tf-m-user-guide.trustedfirmware.org/contributing/index.html) section of the documentation.
+The **Trusted-Firmware-M** team
\ No newline at end of file
diff --git a/ci/TrustedFirmware-M_pr_comment.md b/ci/TrustedFirmware-M_pr_comment.md
new file mode 100644
index 0000000..a9e03ff
--- /dev/null
+++ b/ci/TrustedFirmware-M_pr_comment.md
@@ -0,0 +1,21 @@
+Hello @{user_name}!
+
+
+Thank you for your contribution to **Trusted-Firmware-M**!
+
+This is a read only mirror. Please read the
+["Contributing"](https://tf-m-user-guide.trustedfirmware.org/contributing/index.html)
+section of our documentation and resubmit your changes to the repository hosted in
+[gerrit](https://review.trustedfirmware.org/admin/repos/TF-M/trusted-firmware-m).
+Sorry for the inconveniences!
+
+You can find more information about the project on the
+[projects homepage](https://www.trustedfirmware.org/projects/tf-m).
+
+## What if I face any problems?
+Please drop an email to our [public mailing list](https://lists.trustedfirmware.org/mailman3/lists/tf-m.lists.trustedfirmware.org/).
+[Here](https://lists.trustedfirmware.org/mailman3/lists) you can also find all the mailing lists for all the projects hosted under trustedfirmware.org.
+
+We are looking forward to seeing your changes submitted!
+
+The **Trusted-Firmware-M** team
diff --git a/ci/github_autoreply_bot.py b/ci/github_autoreply_bot.py
new file mode 100755
index 0000000..cd8ce66
--- /dev/null
+++ b/ci/github_autoreply_bot.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+import argparse
+import datetime
+import sys
+import os.path
+import logging
+
+try:
+ from github import Github
+ from github import Auth
+except ImportError:
+ print(
+ "Can not import from github. PyGitHub may be missing."
+ )
+ sys.exit(1)
+
+SCRIPT_DIR = os.path.dirname(__file__)
+
+
+def commented_already(comments, bot):
+ """Check if our bots have left a comment."""
+ return any(comment.user.login == bot for comment in comments)
+
+
+def readfile(path):
+ """Read a file into a python string"""
+ try:
+ with open(os.path.join(SCRIPT_DIR, path), "r") as textfile:
+ comment = textfile.read()
+ except FileNotFoundError:
+ print(f"Can not fine comment template file \"{path}\"")
+ sys.exit(1)
+ else:
+ return comment
+
+
+def reply_to_issue(repo, issue_num):
+ """Reply to the new issues"""
+ comment_file = f"{repo.owner.login}_issue_comment.md"
+ issue = repo.get_issue(number = issue_num)
+ body = readfile(comment_file)
+ if not commented_already(issue.get_comments(), "openci-bot"):
+ print(f"""Using the comment template "{comment_file}" to response {repo.full_name} issue#{issue_num}""")
+ issue.create_comment(body.format(user_name=issue.user.login))
+ else:
+ print(f"We've already commented on the issue#{issue_num}")
+
+
+def reply_to_pr(repo, pr_num):
+ """Reply to the new Pull Request"""
+ comment_file = f"{repo.owner.login}_pr_comment.md"
+ pr = repo.get_pull(number = pr_num)
+ body = readfile(comment_file)
+ if not commented_already(pr.get_comments(), "openci-bot"):
+ print(f"""Using the comment template "{comment_file}" to response {repo.full_name} PR#{pr_num}""")
+ pr.create_issue_comment(body.format(user_name=pr.user.login))
+ else:
+ print(f"We've already commented on the pull request{pr_num}")
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--token", required=True, help="GitHub access token")
+ parser.add_argument("--repo", required=True, help="GitHub repository")
+ group = parser.add_mutually_exclusive_group()
+ group.add_argument("--issue_num", type=int, help="Github issue number")
+ group.add_argument("--pr_num", type=int, help="Github pull reuqest number")
+ args = parser.parse_args()
+
+ auth = Auth.Token(args.token)
+ gh = Github(auth=auth)
+
+ try:
+ repo = gh.get_repo(args.repo)
+ except:
+ print(f"Can not get Github repo {args.repo}")
+ sys.exit(1)
+
+ if args.issue_num:
+ reply_to_issue(repo, args.issue_num)
+ if args.pr_num:
+ reply_to_pr(repo, args.pr_num)
diff --git a/ci/run_github_autoreply.sh b/ci/run_github_autoreply.sh
new file mode 100755
index 0000000..dc94c76
--- /dev/null
+++ b/ci/run_github_autoreply.sh
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2023, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# Install PyGitHub if needed
+python3 -c "import github"
+if [ $? != 0 ]
+then
+ yes | pip3 install pygithub
+fi
+
+# Run bot
+if [ -z "${github_issue_num}" -a -z "${github_pr_num}" ]; then
+ echo "We need one of github_issue_num or github_pr_num"
+ exit 1
+fi
+opts="--token ${AUTH_TOKEN} --repo ${github_repo_full_name}"
+[ -n "${github_issue_num}" ] && opts="${opts} --issue_num ${github_issue_num}"
+[ -n "${github_pr_num}" ] && opts="${opts} --pr_num ${github_pr_num}"
+python3 $(dirname "${BASH_SOURCE[0]}")/github_autoreply_bot.py ${opts}
diff --git a/tf-github-autoresponse.yaml b/tf-github-autoresponse.yaml
new file mode 100644
index 0000000..4e9c110
--- /dev/null
+++ b/tf-github-autoresponse.yaml
@@ -0,0 +1,46 @@
+- job:
+ block-downstream: false
+ block-upstream: false
+ disabled: false
+ name: tf-github-autoresponse
+ display-name: 'TF Github auto response'
+ project-type: freestyle
+ node: master
+ builders:
+ - shell: |-
+ #!/bin/bash
+ echo "########################################################################"
+ echo " Github Environment"
+ env |grep '^github_'
+ echo "########################################################################"
+ bash tf-ci-scripts/ci/run_github_autoreply.sh
+ properties:
+ - build-discarder:
+ days-to-keep: 30
+ num-to-keep: 100
+ scm:
+ - git:
+ branches:
+ - master
+ clean:
+ before: true
+ url: https://review.trustedfirmware.org/ci/tf-ci-scripts
+ basedir: tf-ci-scripts
+ triggers:
+ - generic-webhook-trigger:
+ post-content-params:
+ - type: JSONPath
+ key: github_repo_full_name
+ value: $.repository.full_name
+ - type: JSONPath
+ key: github_issue_num
+ value: $.issue.number
+ - type: JSONPath
+ key: github_pr_num
+ value: $.pull_request.number
+ token: trustedfirmware_github_auto_response
+ wrappers:
+ - credentials-binding:
+ - text:
+ credential-id: openci-bot-github-token
+ variable: AUTH_TOKEN