Sync job files with internal CI
Sync job files with platform-ci commit:
539c151d0cd99a5e6ca6c0e6966f6d8579fe864e
Signed-off-by: Zelalem <zelalem.aweke@arm.com>
Change-Id: Ida470e00da76188ce3987d1fa93ec758b5e0f23a
diff --git a/job/tf-github-autoreply/github_pr_bot.py b/job/tf-github-autoreply/github_pr_bot.py
new file mode 100755
index 0000000..b21da50
--- /dev/null
+++ b/job/tf-github-autoreply/github_pr_bot.py
@@ -0,0 +1,97 @@
+#!/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
+except ImportError:
+ print(
+ "Can not import from github. PyGitHub may be missing. Check requirements.txt."
+ )
+ sys.exit(1)
+
+SCRIPT_DIR = os.path.dirname(__file__)
+logger = logging.getLogger()
+
+
+def commented_already(comments, bots):
+ """Check if our bots have left a comment."""
+ return any(comment.user.login in bots for comment in comments)
+
+
+def readfile(path):
+ """Read a file into a python string"""
+ with open(os.path.join(SCRIPT_DIR, path), "r") as textfile:
+ return textfile.read()
+
+
+def reply_to_issues(repo, bots, dry_run):
+ """Reply to all new issues without a bot reply"""
+ body = readfile("issue_comment.md")
+ logging.info("Replying to new issues on {}/{}".format(repo.owner.login, repo.name))
+ for issue in repo.get_issues(since=datetime.datetime(2019, 10, 17, 12)):
+ if not commented_already(issue.get_comments(), bots):
+ logging.info("Repliyng to issue #{}: {}".format(issue.number, issue.title))
+ if not dry_run:
+ issue.create_comment(body.format(user_name=issue.user.login))
+
+
+def reply_to_pull_requests(repo, bots, dry_run):
+ """Reply to all new Pull Requests without a bot reply"""
+ body = readfile("pull_comment.md")
+ logging.info("Replying to PRs on {}/{}".format(repo.owner.login, repo.name))
+ for pr in repo.get_pulls("status=open"):
+ # get_issue_comments() returns top-level PR comments.
+ # While get_comments() or get_review_comments()
+ # return comments against diff in the PR.
+ if not commented_already(pr.get_issue_comments(), bots):
+ logging.info("Repling to pull request #{}: {}".format(pr.number, pr.title))
+ if not dry_run:
+ pr.create_issue_comment(body.format(user_name=pr.user.login))
+
+
+def to_repo(gh, owner, name):
+ """Construct a Repo from a logged in Github object an owner and a repo name"""
+ return gh.get_user(owner).get_repo(name)
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser()
+ parser.add_argument("user", help="Username to login to GitHub")
+ parser.add_argument("pass", help="Password of the GitHub user")
+ parser.add_argument(
+ "--dry-run",
+ help="Just print what would be done",
+ default=False,
+ action="store_true",
+ )
+ parser.add_argument('--verbose', '-v', action='count', default=0, help="Increase verbosity of the printing")
+ args = parser.parse_args()
+
+ if args.verbose <= 0:
+ logger.setLevel(logging.ERROR)
+ elif args.verbose <= 1:
+ logger.setLevel(logging.INFO)
+ else:
+ logger.setLevel(logging.DEBUG)
+
+ repository_owner = "ARM-software"
+ repository_name = "arm-trusted-firmware"
+ issues_name = "tf-issues"
+ bots = {"arm-tf-bot", "ssg-bot", args.user}
+
+ gh = Github(args.user, getattr(args, "pass"))
+ pr_repo = to_repo(gh, repository_owner, repository_name)
+ reply_to_pull_requests(pr_repo, bots, args.dry_run)
+ issue_repo = to_repo(gh, repository_owner, issues_name)
+ reply_to_pull_requests(issue_repo, bots, args.dry_run)
+ reply_to_issues(issue_repo, bots, args.dry_run)
diff --git a/job/tf-github-autoreply/issue_comment.md b/job/tf-github-autoreply/issue_comment.md
new file mode 100644
index 0000000..fb4d721
--- /dev/null
+++ b/job/tf-github-autoreply/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/job/tf-github-autoreply/pull_comment.md b/job/tf-github-autoreply/pull_comment.md
new file mode 100644
index 0000000..0418224
--- /dev/null
+++ b/job/tf-github-autoreply/pull_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/job/tf-github-autoreply/requirements.txt b/job/tf-github-autoreply/requirements.txt
new file mode 100644
index 0000000..3aa2f44
--- /dev/null
+++ b/job/tf-github-autoreply/requirements.txt
@@ -0,0 +1,9 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+#github_pr_bot.py requires:
+
+pygithub>=1.44
diff --git a/job/tf-github-autoreply/run_github_autoreply.sh b/job/tf-github-autoreply/run_github_autoreply.sh
new file mode 100755
index 0000000..63c4466
--- /dev/null
+++ b/job/tf-github-autoreply/run_github_autoreply.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+#
+# Copyright (c) 2020, 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
+python3 $(dirname "${BASH_SOURCE[0]}")/github_pr_bot.py $@