You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/08/07 19:18:21 UTC

[GitHub] CathyZhang0822 commented on a change in pull request #11861: [MXNET-691] Add Email Bot

CathyZhang0822 commented on a change in pull request #11861: [MXNET-691] Add Email Bot
URL: https://github.com/apache/incubator-mxnet/pull/11861#discussion_r208354154
 
 

 ##########
 File path: mxnet-bot/EmailBot/EmailBot.py
 ##########
 @@ -0,0 +1,304 @@
+# 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.
+
+from __future__ import print_function
+from botocore.exceptions import ClientError
+from botocore.vendored import requests
+from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
+import boto3
+import boto3.s3
+import datetime
+import logging
+import os
+import re
+
+logging.basicConfig(level=logging.INFO)
+logging.getLogger('boto3').setLevel(logging.CRITICAL)
+logging.getLogger('botocore').setLevel(logging.CRITICAL)
+
+LOGGER = logging.getLogger(__name__)
+
+
+class EmailBot:
+
+    # GitHub account credentials
+    GITHUB_USER = os.environ.get("GITHUB_USER")
+    GITHUB_OAUTH_TOKEN = os.environ.get("GITHUB_OAUTH_TOKEN")
+    AUTH = (GITHUB_USER, GITHUB_OAUTH_TOKEN)
+    REPO = os.environ.get("REPO")
+    # Send emails using Amazon Simple Email Service(SES)
+    # Sender's email address must be verified.
+    # Replace it with sender's email address
+    sender = "sender@email.com"
+    # Recipients' email address must be verified
+    # Replace it with recipients' email addresses
+    recipients = ["recipient1@email.com", "recipient2@email.com"]
+    # If necessary, replace us-west-2 with the AWS Region you're using for Amazon SES.
+    aws_region = "us-west-2"
+    # sla
+    sla = 5
+
+    def __init__(self):
+        self.opendata = None
+        self.closeddata = None
+        # Because GitHub use UTC time, so we set self.end 2 days after today's date
+        # For example:
+        # self.today = "2018-07-10 00:00:00"
+        # self.end = "2018-07-12 00:00:00"
+        # self.start = "2018-07-04 00:00:00"
+        self.start = datetime.datetime.strptime("2015-01-01", "%Y-%m-%d")
+        self.end = datetime.datetime.today()+datetime.timedelta(days=2)
+
+    def __clean_string(self, raw_string, sub_string):
+        # covert all non-alphanumeric characters from raw_string to sub_string
+        cleans = re.sub("[^0-9a-zA-Z]", sub_string, raw_string)
+        return cleans.lower()
+
+    def __set_period(self, period):
+        # set the time period, ex: set_period(7)
+        today = datetime.datetime.strptime(str(datetime.datetime.today().date()), "%Y-%m-%d")
+        self.end = today + datetime.timedelta(days=2)
+        timedelta = datetime.timedelta(days=period)
+        self.start = self.end - timedelta
+
+    def __count_pages(self, obj, state='all'):
+        # This method is to count how many pages of issues/labels in total
+        # obj could be "issues"/"labels"
+        # state could be "open"/"closed"/"all", available to issues
+        assert obj in set(["issues", "labels"]), "Invalid Input!"
+        url = 'https://api.github.com/repos/{}/{}'.format(self.REPO, obj)
+        if obj == 'issues':
+            response = requests.get(url, {'state': state},
+                                    auth=self.AUTH)
+        else:
+            response = requests.get(url, auth=self.AUTH)
+        assert response.headers["Status"] == "200 OK", response.headers["Status"]
+        if "link" not in response.headers:
+            # That means only 1 page exits
+            return 1
+        # response.headers['link'] will looks like:
+        # <https://api.github.com/repositories/34864402/issues?state=all&page=387>; rel="last"
+        # In this case we need to extrac '387' as the count of pages
+        return int(self.__clean_string(response.headers['link'], " ").split()[-3])
+
+    def read_repo(self, periodically=True):
 
 Review comment:
   Done. All methods descriptions are added. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services