Commit 9b23d069 authored by Matthieu Boileau's avatar Matthieu Boileau
Browse files

Update .gitlab-ci.yml

remove "docker" branch from .gitlab-ci.yml
parent 73bbac7b
......@@ -87,6 +87,6 @@ notify-job-offer-author:
variables:
- $CI_COMMIT_TITLE =~ /^Merge branch 'job_.*$/
script:
- python3 utils/notify_job_offer.py --commit_title "$CI_COMMIT_TITLE" --password $SENDER_PASSWORD --notifier author
- python3 utils/notify_job_offer.py --commit_title "$CI_COMMIT_TITLE" --password $SENDER_PASSWORD --notifier list --recipient_email $GITLAB_USER_EMAIL
- python3 utils/notify_job_offer.py --commit_title "$CI_COMMIT_TITLE" --password $SENDER_PASSWORD --notifier author --publisher "$GITLAB_USER_NAME"
- python3 utils/notify_job_offer.py --commit_title "$CI_COMMIT_TITLE" --password $SENDER_PASSWORD --notifier list --recipient_email $GITLAB_USER_EMAIL --publisher "$GITLAB_USER_NAME"
......@@ -33,12 +33,20 @@ class Message:
subject = ""
template = Template("")
def __init__(self, job_id, recipient_email=None):
def __init__(self, job_id, recipient_email=None, publisher=None):
self.job_id = job_id
self.job_url = "{}/job_{}.html".format(SITEURL, self.job_id)
self.parse_job_offer_file()
self.recipient_name = None
self.recipient_email = recipient_email
job_url = "{}/job_{}.html".format(SITEURL, self.job_id)
self.d = {'JOB_URL': job_url}
if publisher:
self.d['PUBLISHER_MESSAGE'] = "{}, pour le".format(publisher.title())
else:
self.d['PUBLISHER_MESSAGE'] = 'Le'
def parse_job_offer_file(self):
filename = f"../content/job_offers/job_{self.job_id}.md"
filepath = os.path.join(script_path, filename)
......@@ -93,7 +101,7 @@ Sans demande de votre part, elle restera en ligne jusqu'au $EXPIRE_DATE.
Cordialement,
Le bureau du groupe Calcul.
$PUBLISHER_MESSAGE bureau du groupe Calcul.
""")
def __init__(self, *args, **kwargs):
......@@ -108,10 +116,9 @@ Le bureau du groupe Calcul.
expire_date = datetime.date.today() + datetime.timedelta(days=90)
d = {'JOB_URL': self.job_url,
'EXPIRE_DATE': '{d.day} {d:%B} {d.year}'.format(d=expire_date)}
self.d['EXPIRE_DATE'] = '{d.day} {d:%B} {d.year}'.format(d=expire_date)
body = self.template.substitute(d)
body = self.template.substitute(self.d)
return body
......@@ -128,7 +135,7 @@ Vous en retrouverez tous les détails sur $JOB_URL.
Cordialement,
Le bureau du groupe Calcul.
$PUBLISHER_MESSAGE bureau du groupe Calcul.
""")
def __init__(self, *args, **kwargs):
......@@ -142,24 +149,23 @@ Le bureau du groupe Calcul.
def get_email_body(self):
"""Return email body from template"""
d = {'JOB_URL': self.job_url,
'JOB_AUTHOR': self.author_name,
'JOB_TYPE': self.job_type,
'JOB_TITLE': self.job_title}
self.d['JOB_AUTHOR'] = self.author_name
self.d['JOB_TYPE'] = self.job_type
self.d['JOB_TITLE'] = self.job_title
body = self.template.substitute(d)
body = self.template.substitute(self.d)
return body
def send_email(commit_title=None, job_id=None, password=None, notifier=None, recipient_email=None):
def send_email(commit_title=None, job_id=None, password=None, notifier=None, recipient_email=None, publisher=None):
"""Send notification email using smtplib"""
if not job_id:
m = re.match("^Merge branch 'job_(.*)' into '(.*)'$", commit_title)
job_id = m.group(1)
message = notifier(job_id, recipient_email)
message = notifier(job_id, recipient_email, publisher)
msg = message.get_msg()
if not password:
......@@ -184,17 +190,20 @@ def main():
help="Type for notifying message")
parser.add_argument('--recipient_email', nargs=1, metavar="recipent-email-address",
help="Override default (author or list address)")
parser.add_argument('--publisher', nargs=1, metavar="publish-name",
help="Name of Groupe Calcul's member responsible for publishing the job offer.")
args = parser.parse_args()
password = args.password[0] if args.password else None
notifier = {"author": AuthorMessage, "list": ListMessage}
recipient_email = args.recipient_email[0] if args.recipient_email else None
publisher = args.publisher[0] if args.publisher else None
if args.commit_title:
send_email(commit_title=args.commit_title[0], password=password, notifier=notifier[args.notifier[0]],
recipient_email=recipient_email)
recipient_email=recipient_email, publisher=publisher)
elif args.job_id:
send_email(job_id=args.job_id[0], password=password, notifier=notifier[args.notifier[0]],
recipient_email=recipient_email)
recipient_email=recipient_email, publisher=publisher)
if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment