From f9c32fb3ce8786b9833e9414c065cbeea024d566 Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Thu, 4 Apr 2019 17:13:21 +0200 Subject: [PATCH 01/31] Update .gitlab-ci.yml remove "docker" branch from .gitlab-ci.yml --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 15460538..541348c5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -36,7 +36,6 @@ apache-dev: - pr_branch_deploy - TEST-job-form - theme - - docker - develop - /^dev-.*$/ - embed_twitter_v2 -- GitLab From 4ddbddd7d5cf61bd2d384fcbb7de3f57a59af7ee Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Thu, 4 Apr 2019 21:23:28 +0200 Subject: [PATCH 02/31] Address #57 --- .gitlab-ci.yml | 9 +++ utils/notify_job_offer_author.py | 131 +++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 utils/notify_job_offer_author.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 541348c5..09f37eb2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -72,3 +72,12 @@ update-issue: script: - echo "Updating issue \#49" - python3 utils/follow_transfer.py --issue + +notify-job-offer-author: + only: + - master + - develop + variables: + - $CI_COMMIT_MESSAGE =~ /^Adding new job offer job_.*$/ + script: + - python3 utils/notify_job_offer_author.py --commit_message "$CI_COMMIT_MESSAGE" --password $SENDER_PASSWORD diff --git a/utils/notify_job_offer_author.py b/utils/notify_job_offer_author.py new file mode 100644 index 00000000..408a77f5 --- /dev/null +++ b/utils/notify_job_offer_author.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python3 +"""Email belenios vote credentials to voters""" + +import argparse +import smtplib +from email.message import EmailMessage +from email.headerregistry import Address +from string import Template +import getpass +import os +import re +import sys +import datetime +import locale +locale.setlocale(locale.LC_TIME, '') +script_path = os.path.dirname(sys.argv[0]) +sys.path.append(os.path.join(script_path, '..')) +from publishconf import SITEURL + + +# Email +SUBJECT = "Votre annonce d'offre d'emploi a été validée" +MAILSERVER = 'mailserver.u-strasbg.fr' +SENDER_ACCOUNT = 'math-gitlab-incoming' +SENDER_MAIL = "calcul-contact@math.cnrs.fr" +SENDER_NAME = "Bureau du groupe Calcul" +SENDER_ACCOUNT_DISPLAY = "calcul-contact" +SENDER_DOMAIN = "math.cnrs.fr" + + +class Bcolors: + """For printing colored output to terminal""" + OKGREEN = '\033[32m' + WARNING = '\033[33m' + FAIL = '\033[31m' + ENDC = '\033[0m' + + +STATUS_OK = "{}{:<4}{}".format(Bcolors.OKGREEN, "OK", Bcolors.ENDC) +STATUS_WARN = "{}{:<4}{}".format(Bcolors.WARNING, "Warn", Bcolors.ENDC) +STATUS_KO = "{}{:<4}{}".format(Bcolors.FAIL, "KO", Bcolors.ENDC) + + +TEMPLATE = Template("""\ +Bonjour, + +Merci d'avoir déposé une annonce d'offre d'emploi sur le site web du groupe Calcul. +Cette annonce a été validée par le bureau du groupe Calcul et vient d'être : + + - publiée sur $JOB_URL + - diffusée sur la liste calcul@listes.math.cnrs.fr. + +Sans demande de votre part, elle restera en ligne jusqu'au $DATE_PUB. + +Cordialement, + +Le bureau du groupe Calcul. + +""") + + +def send_email(commit_message, password=None, ): + """Send notification email using smtplib""" + + def prompt_for_password(): + return getpass.getpass(f"Please type email password for {SENDER_MAIL}: ") + + if not password: + password = prompt_for_password() + + # Connect to SMTP + with smtplib.SMTP_SSL(MAILSERVER) as smtp: + while True: + try: + smtp.login(SENDER_ACCOUNT, password) + break + except smtplib.SMTPAuthenticationError: + print("Authentication error. Please retry.") + password = prompt_for_password() + + d = {} + + m = re.match("^Adding new job offer job_(.*)$", commit_message) + job_id = m.group(1) + + d['JOB_URL'] = f"{SITEURL}/job_{job_id}.html" + + filename = f"../content/job_offers/job_{job_id}.md" + filepath = os.path.join(script_path, filename) + + with open(filepath) as f: + s = f.read() + # TODO: When expire_date will be in job_*.md file + # m = re.search("Date: (.*)$", s, re.MULTILINE) + # date = m.group(1) + #expire_date to format... + m = re.search("Authors: (.*)$", s, re.MULTILINE) + author_name = m.group(1) + m = re.search("Email: (.*)$", s, re.MULTILINE) + author_email = m.group(1) + + expire_date = datetime.date.today() + datetime.timedelta(days=90) + + d['DATE_PUB'] = '{d.day} {d:%B} {d.year}'.format(d=expire_date) + msg = EmailMessage() + msg['Subject'] = SUBJECT + msg['From'] = Address(SENDER_NAME, SENDER_ACCOUNT_DISPLAY, SENDER_DOMAIN) + msg['To'] = author_email + body = TEMPLATE.substitute(d) + msg.set_content(body) + print(body) + + print(f">>> Sending notification to {author_name} <{author_email}>") + #smtp.sendmail(SENDER_MAIL, author_email, msg.as_string()) + + +def main(): + """Read CLI to send email""" + parser = argparse.ArgumentParser(description="Send email notification to the author of job offer") + parser.add_argument('--commit_message', nargs=1, metavar='commit-message', required=True) + parser.add_argument('--password', nargs=1, metavar="account-password", help="password for sender email account") + args = parser.parse_args() + + if args.password: + send_email(args.commit_message[0], password=args.password[0]) + else: + send_email(args.job_url[0]) + + +if __name__ == '__main__': + main() -- GitLab From 6bba146369ce6fa69bdddea3f3c2414d6b7527be Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Thu, 4 Apr 2019 22:21:21 +0200 Subject: [PATCH 03/31] Update .gitlab-ci.yml correct syntax --- .gitlab-ci.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 09f37eb2..c6d24dfa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,6 +2,7 @@ stages: - deps - build - deploy + - post-deploy deps: stage: deps @@ -62,7 +63,7 @@ apache: - rsync -av --delete content/attachments/ $PUBLISH_DIR/attachments/ update-issue: - stage: deploy + stage: post-deploy image: $CI_REGISTRY_IMAGE tags: - docker @@ -74,10 +75,12 @@ update-issue: - python3 utils/follow_transfer.py --issue notify-job-offer-author: + stage: post-deploy only: - master - develop + only: variables: - $CI_COMMIT_MESSAGE =~ /^Adding new job offer job_.*$/ - script: - - python3 utils/notify_job_offer_author.py --commit_message "$CI_COMMIT_MESSAGE" --password $SENDER_PASSWORD + script: + - python3 utils/notify_job_offer_author.py --commit_message "$CI_COMMIT_MESSAGE" --password $SENDER_PASSWORD -- GitLab From 776ac1cc173bb0ea93e5d4239c05fb2ba94d1dba Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Thu, 4 Apr 2019 22:29:18 +0200 Subject: [PATCH 04/31] gitlab-ci: Add dev-branches to notify job --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c6d24dfa..28095572 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -79,6 +79,7 @@ notify-job-offer-author: only: - master - develop + - /^dev-.*$/ only: variables: - $CI_COMMIT_MESSAGE =~ /^Adding new job offer job_.*$/ -- GitLab From ceb7c66c86cad0c9bfc9f54511f755a729a0d062 Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Thu, 4 Apr 2019 22:36:43 +0200 Subject: [PATCH 05/31] Update gitlab_config.py temporary change for testing --- content/job_offers/gitlab_config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/job_offers/gitlab_config.py b/content/job_offers/gitlab_config.py index 37660e2c..ffbb8683 100644 --- a/content/job_offers/gitlab_config.py +++ b/content/job_offers/gitlab_config.py @@ -2,7 +2,8 @@ GITLAB_URL = "https://gitlab.math.unistra.fr" GITLAB_TOKEN = "oH9EHD7FU4A8sPHgdoDP" GITLAB_TARGET_ID = 309 # groupe-calcul/website -GITLAB_TARGET_BRANCH = 'develop' +#GITLAB_TARGET_BRANCH = 'develop' +GITLAB_TARGET_BRANCH = 'dev-boileau' GITLAB_SOURCE_ID = 309 # groupe-calcul/website GITLAB_REF_BRANCH = GITLAB_TARGET_BRANCH # Head of the job branch GITLAB_LABELS = ["Offre d'emploi"] -- GitLab From 66f432a0225f27b6dc7ee153772258ba116767b0 Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Thu, 4 Apr 2019 22:39:41 +0200 Subject: [PATCH 06/31] Update notify_job_offer_author.py actually send notification --- utils/notify_job_offer_author.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/notify_job_offer_author.py b/utils/notify_job_offer_author.py index 408a77f5..fc443c15 100644 --- a/utils/notify_job_offer_author.py +++ b/utils/notify_job_offer_author.py @@ -111,7 +111,7 @@ def send_email(commit_message, password=None, ): print(body) print(f">>> Sending notification to {author_name} <{author_email}>") - #smtp.sendmail(SENDER_MAIL, author_email, msg.as_string()) + smtp.sendmail(SENDER_MAIL, author_email, msg.as_string()) def main(): -- GitLab From cfa43e5e4534c610d8a1ad8b5847205725abdd31 Mon Sep 17 00:00:00 2001 From: Calcul Bot Date: Thu, 4 Apr 2019 22:43:25 +0200 Subject: [PATCH 07/31] Adding new job offer job_4175e3e8172f470ee5434ce3a1309f42 --- .../job_4175e3e8172f470ee5434ce3a1309f42.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 content/job_offers/job_4175e3e8172f470ee5434ce3a1309f42.md diff --git a/content/job_offers/job_4175e3e8172f470ee5434ce3a1309f42.md b/content/job_offers/job_4175e3e8172f470ee5434ce3a1309f42.md new file mode 100644 index 00000000..cceb96b2 --- /dev/null +++ b/content/job_offers/job_4175e3e8172f470ee5434ce3a1309f42.md @@ -0,0 +1,26 @@ +Title: Testeur de formulaire +Date: 2019-04-04 22:43 +Slug: job_4175e3e8172f470ee5434ce3a1309f42 +Category: job +Authors: Matthieu Boileau +Email: matthieu.boileau@math.unistra.fr +Job_Type: Stage +Tags: stage +Template: job_offer +Job_Location: Strasbourg +Job_Duration: Une semaine +Job_Website: https://www.irma.math.unistra.fr +Job_Employer: CNRS +Attachment: + +## Programme : + +- tester les champs +- vérifier les notifications +- tester la *syntaxe* **markdown** <https://calcul.math.cnrs.fr> + + +## Compétences + +- cliquer sur des boutons +- taper au clavier -- GitLab From 3d5ea87498b702983053cbe847c3a1de49237cd3 Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Thu, 4 Apr 2019 22:48:16 +0200 Subject: [PATCH 08/31] Update .gitlab-ci.yml add tag --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 28095572..c40f2281 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -76,6 +76,9 @@ update-issue: notify-job-offer-author: stage: post-deploy + image: $CI_REGISTRY_IMAGE + tags: + - docker only: - master - develop -- GitLab From 936a0a7b14440f359ee7cdc4572110ea12ce6b0e Mon Sep 17 00:00:00 2001 From: Calcul Bot Date: Thu, 4 Apr 2019 22:50:42 +0200 Subject: [PATCH 09/31] Adding new job offer job_b161674a75dc54d4bd08925e7a9d5b44 --- .../job_b161674a75dc54d4bd08925e7a9d5b44.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 content/job_offers/job_b161674a75dc54d4bd08925e7a9d5b44.md diff --git a/content/job_offers/job_b161674a75dc54d4bd08925e7a9d5b44.md b/content/job_offers/job_b161674a75dc54d4bd08925e7a9d5b44.md new file mode 100644 index 00000000..579eb53a --- /dev/null +++ b/content/job_offers/job_b161674a75dc54d4bd08925e7a9d5b44.md @@ -0,0 +1,26 @@ +Title: Testeur de formulaire +Date: 2019-04-04 22:50 +Slug: job_b161674a75dc54d4bd08925e7a9d5b44 +Category: job +Authors: Matthieu Boileau +Email: matthieu.boileau@math.unistra.fr +Job_Type: Stage +Tags: stage +Template: job_offer +Job_Location: Strasbourg +Job_Duration: Une semaine +Job_Website: https://www.irma.math.unistra.fr +Job_Employer: CNRS +Attachment: + +## Programme : + +- tester les champs +- vérifier les notifications +- tester la *syntaxe* **markdown** <https://calcul.math.cnrs.fr> + + +## Compétences + +- cliquer sur des boutons +- taper au clavier -- GitLab From 8b37992449b4b577170a16ac4baf1f5e391e7af6 Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Thu, 4 Apr 2019 23:01:44 +0200 Subject: [PATCH 10/31] Update notify_job_offer_author.py --- utils/notify_job_offer_author.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utils/notify_job_offer_author.py b/utils/notify_job_offer_author.py index fc443c15..f650ae08 100644 --- a/utils/notify_job_offer_author.py +++ b/utils/notify_job_offer_author.py @@ -82,8 +82,10 @@ def send_email(commit_message, password=None, ): m = re.match("^Adding new job offer job_(.*)$", commit_message) job_id = m.group(1) + print("job_id:", job_id) d['JOB_URL'] = f"{SITEURL}/job_{job_id}.html" + print("d['JOB_URL']:", d['JOB_URL']) filename = f"../content/job_offers/job_{job_id}.md" filepath = os.path.join(script_path, filename) -- GitLab From 539bd7f2dd843ea9590d370eb599bce9912ac368 Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Thu, 4 Apr 2019 23:06:02 +0200 Subject: [PATCH 12/31] Adding new job offer job_b161674a75dc54d4bd08925e7a9d5b44 --- utils/notify_job_offer_author.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/notify_job_offer_author.py b/utils/notify_job_offer_author.py index f650ae08..0c22d20a 100644 --- a/utils/notify_job_offer_author.py +++ b/utils/notify_job_offer_author.py @@ -84,7 +84,7 @@ def send_email(commit_message, password=None, ): job_id = m.group(1) print("job_id:", job_id) - d['JOB_URL'] = f"{SITEURL}/job_{job_id}.html" + d['JOB_URL'] = "{}/job_{}.html".format(SITEURL, job_id) print("d['JOB_URL']:", d['JOB_URL']) filename = f"../content/job_offers/job_{job_id}.md" -- GitLab From 4cb3aef59ee80e51f71af45d4f848a4ff14ce66f Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Thu, 4 Apr 2019 23:07:55 +0200 Subject: [PATCH 13/31] Update notify_job_offer_author.py Some corrections --- utils/notify_job_offer_author.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/utils/notify_job_offer_author.py b/utils/notify_job_offer_author.py index fc443c15..bbbcabf5 100644 --- a/utils/notify_job_offer_author.py +++ b/utils/notify_job_offer_author.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Email belenios vote credentials to voters""" +"""Email confirmation to job offer author""" import argparse import smtplib @@ -83,7 +83,7 @@ def send_email(commit_message, password=None, ): m = re.match("^Adding new job offer job_(.*)$", commit_message) job_id = m.group(1) - d['JOB_URL'] = f"{SITEURL}/job_{job_id}.html" + d['JOB_URL'] = "{}/job_{}.html".format(SITEURL, job_id) filename = f"../content/job_offers/job_{job_id}.md" filepath = os.path.join(script_path, filename) @@ -108,9 +108,10 @@ def send_email(commit_message, password=None, ): msg['To'] = author_email body = TEMPLATE.substitute(d) msg.set_content(body) - print(body) print(f">>> Sending notification to {author_name} <{author_email}>") + print(body) + smtp.sendmail(SENDER_MAIL, author_email, msg.as_string()) @@ -124,7 +125,7 @@ def main(): if args.password: send_email(args.commit_message[0], password=args.password[0]) else: - send_email(args.job_url[0]) + send_email(args.commit_message[0]) if __name__ == '__main__': -- GitLab From 6ed9aebb7c307e6778752c1fb5959b68a26048d7 Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Thu, 4 Apr 2019 23:16:40 +0200 Subject: [PATCH 14/31] Update .gitlab-ci.yml fix syntax --- .gitlab-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c40f2281..49485092 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -80,10 +80,10 @@ notify-job-offer-author: tags: - docker only: - - master - - develop - - /^dev-.*$/ - only: + refs: + - master + - develop + - /^dev-.*$/ variables: - $CI_COMMIT_MESSAGE =~ /^Adding new job offer job_.*$/ script: -- GitLab From d4bb8ed54e4b7ff15e92f6b925f8710b0dfe0dfd Mon Sep 17 00:00:00 2001 From: Calcul Bot Date: Thu, 4 Apr 2019 23:18:36 +0200 Subject: [PATCH 15/31] Adding new job offer job_f70cfa3e52baa9b6558110b6d1704efc --- .../job_f70cfa3e52baa9b6558110b6d1704efc.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 content/job_offers/job_f70cfa3e52baa9b6558110b6d1704efc.md diff --git a/content/job_offers/job_f70cfa3e52baa9b6558110b6d1704efc.md b/content/job_offers/job_f70cfa3e52baa9b6558110b6d1704efc.md new file mode 100644 index 00000000..71fd54ce --- /dev/null +++ b/content/job_offers/job_f70cfa3e52baa9b6558110b6d1704efc.md @@ -0,0 +1,22 @@ +Title: Testeur de formulaire +Date: 2019-04-04 23:18 +Slug: job_f70cfa3e52baa9b6558110b6d1704efc +Category: job +Authors: Matthieu Boileau +Email: matthieu.boileau@math.unistra.fr +Job_Type: Stage +Tags: stage +Template: job_offer +Job_Location: Strasbourg +Job_Duration: Une semaine +Job_Website: https://www.irma.math.unistra.fr +Job_Employer: CNRS +Attachment: + +Programme : +tester les champs +vérifier les notifications +tester la syntaxe markdown <https://calcul.math.cnrs.fr> +Compétences +cliquer sur des boutons +taper au clavier \ No newline at end of file -- GitLab From 8261731584a039a006dd9614b96c5173ce08a35f Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Thu, 4 Apr 2019 23:23:15 +0200 Subject: [PATCH 16/31] notification: correct commit message --- .gitlab-ci.yml | 2 +- utils/notify_job_offer_author.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 49485092..ea436862 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -85,6 +85,6 @@ notify-job-offer-author: - develop - /^dev-.*$/ variables: - - $CI_COMMIT_MESSAGE =~ /^Adding new job offer job_.*$/ + - $CI_COMMIT_MESSAGE =~ /^Merge branch 'job_.*$/ script: - python3 utils/notify_job_offer_author.py --commit_message "$CI_COMMIT_MESSAGE" --password $SENDER_PASSWORD diff --git a/utils/notify_job_offer_author.py b/utils/notify_job_offer_author.py index 5607f174..734d6fa7 100644 --- a/utils/notify_job_offer_author.py +++ b/utils/notify_job_offer_author.py @@ -80,7 +80,7 @@ def send_email(commit_message, password=None, ): d = {} - m = re.match("^Adding new job offer job_(.*)$", commit_message) + m = re.match("^Merge branch 'job_(.*)' into '(.*)'$", commit_message) job_id = m.group(1) print("job_id:", job_id) -- GitLab From c3d4a95d760e6cfb8719fb9a22bf7c0571a0b1e1 Mon Sep 17 00:00:00 2001 From: Calcul Bot Date: Thu, 4 Apr 2019 23:24:33 +0200 Subject: [PATCH 17/31] Adding new job offer job_0702192bfa0db6000ba32157b863a5a6 --- .../job_0702192bfa0db6000ba32157b863a5a6.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 content/job_offers/job_0702192bfa0db6000ba32157b863a5a6.md diff --git a/content/job_offers/job_0702192bfa0db6000ba32157b863a5a6.md b/content/job_offers/job_0702192bfa0db6000ba32157b863a5a6.md new file mode 100644 index 00000000..fd3cc012 --- /dev/null +++ b/content/job_offers/job_0702192bfa0db6000ba32157b863a5a6.md @@ -0,0 +1,22 @@ +Title: Testeur de formulaire +Date: 2019-04-04 23:24 +Slug: job_0702192bfa0db6000ba32157b863a5a6 +Category: job +Authors: Matthieu Boileau +Email: matthieu.boileau@math.unistra.fr +Job_Type: Stage +Tags: stage +Template: job_offer +Job_Location: Strasbourg +Job_Duration: Une semaine +Job_Website: https://www.irma.math.unistra.fr +Job_Employer: CNRS +Attachment: + +Programme : +tester les champs +vérifier les notifications +tester la syntaxe markdown <https://calcul.math.cnrs.fr> +Compétences +cliquer sur des boutons +taper au clavier \ No newline at end of file -- GitLab From 3a54ee481bfe61a0ae55ed324776836ee564784f Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Thu, 4 Apr 2019 23:28:59 +0200 Subject: [PATCH 18/31] Update .gitlab-ci.yml export variables for testing --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ea436862..7b9a31fd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,6 +4,9 @@ stages: - deploy - post-deploy +before_script: + - export + deps: stage: deps tags: -- GitLab From 3e06032b880191e577b5f9bcd5d4957015136ce6 Mon Sep 17 00:00:00 2001 From: Calcul Bot Date: Thu, 4 Apr 2019 23:29:19 +0200 Subject: [PATCH 19/31] Adding new job offer job_8d772efed0a69ae9cc692be2fd6a9ab3 --- .../job_8d772efed0a69ae9cc692be2fd6a9ab3.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 content/job_offers/job_8d772efed0a69ae9cc692be2fd6a9ab3.md diff --git a/content/job_offers/job_8d772efed0a69ae9cc692be2fd6a9ab3.md b/content/job_offers/job_8d772efed0a69ae9cc692be2fd6a9ab3.md new file mode 100644 index 00000000..362f527b --- /dev/null +++ b/content/job_offers/job_8d772efed0a69ae9cc692be2fd6a9ab3.md @@ -0,0 +1,22 @@ +Title: Testeur de formulaire +Date: 2019-04-04 23:29 +Slug: job_8d772efed0a69ae9cc692be2fd6a9ab3 +Category: job +Authors: Matthieu Boileau +Email: matthieu.boileau@math.unistra.fr +Job_Type: Stage +Tags: stage +Template: job_offer +Job_Location: Strasbourg +Job_Duration: Une semaine +Job_Website: https://www.irma.math.unistra.fr +Job_Employer: CNRS +Attachment: + +Programme : +tester les champs +vérifier les notifications +tester la syntaxe markdown <https://calcul.math.cnrs.fr> +Compétences +cliquer sur des boutons +taper au clavier \ No newline at end of file -- GitLab From 502b2b63c3c8deb861db954aad9641a94898488e Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Thu, 4 Apr 2019 23:37:30 +0200 Subject: [PATCH 20/31] Update .gitlab-ci.yml escape character in regex --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7b9a31fd..0f652549 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -88,6 +88,6 @@ notify-job-offer-author: - develop - /^dev-.*$/ variables: - - $CI_COMMIT_MESSAGE =~ /^Merge branch 'job_.*$/ + - $CI_COMMIT_MESSAGE =~ /^Merge branch \'job_.*$/ script: - python3 utils/notify_job_offer_author.py --commit_message "$CI_COMMIT_MESSAGE" --password $SENDER_PASSWORD -- GitLab From 4242d5a6b5854d83f284616e9bec62803ed10295 Mon Sep 17 00:00:00 2001 From: Calcul Bot Date: Thu, 4 Apr 2019 23:38:52 +0200 Subject: [PATCH 21/31] Adding new job offer job_9db7ed3285261f292ab3d901f58dfb83 --- .../job_9db7ed3285261f292ab3d901f58dfb83.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 content/job_offers/job_9db7ed3285261f292ab3d901f58dfb83.md diff --git a/content/job_offers/job_9db7ed3285261f292ab3d901f58dfb83.md b/content/job_offers/job_9db7ed3285261f292ab3d901f58dfb83.md new file mode 100644 index 00000000..2c94dcbe --- /dev/null +++ b/content/job_offers/job_9db7ed3285261f292ab3d901f58dfb83.md @@ -0,0 +1,22 @@ +Title: Testeur de formulaire +Date: 2019-04-04 23:38 +Slug: job_9db7ed3285261f292ab3d901f58dfb83 +Category: job +Authors: Matthieu Boileau +Email: matthieu.boileau@math.unistra.fr +Job_Type: Stage +Tags: stage +Template: job_offer +Job_Location: Strasbourg +Job_Duration: Une semaine +Job_Website: https://www.irma.math.unistra.fr +Job_Employer: CNRS +Attachment: + +Programme : +tester les champs +vérifier les notifications +tester la syntaxe markdown <https://calcul.math.cnrs.fr> +Compétences +cliquer sur des boutons +taper au clavier \ No newline at end of file -- GitLab From e7521f691aa9262c82ab358c215604e3d221173c Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Thu, 4 Apr 2019 23:42:16 +0200 Subject: [PATCH 22/31] Update .gitlab-ci.yml CI_COMMIT_TITLE instead of CI_COMMIT_MESSAGE --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0f652549..510ce161 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -88,6 +88,6 @@ notify-job-offer-author: - develop - /^dev-.*$/ variables: - - $CI_COMMIT_MESSAGE =~ /^Merge branch \'job_.*$/ + - $CI_COMMIT_TITLE =~ /^Merge branch 'job_.*$/ script: - - python3 utils/notify_job_offer_author.py --commit_message "$CI_COMMIT_MESSAGE" --password $SENDER_PASSWORD + - python3 utils/notify_job_offer_author.py --commit_message "$CI_COMMIT_TITLE" --password $SENDER_PASSWORD -- GitLab From 1c763ee12ace3ab3d9b3ef44b0518d3c1464c70a Mon Sep 17 00:00:00 2001 From: Calcul Bot Date: Thu, 4 Apr 2019 23:43:27 +0200 Subject: [PATCH 23/31] Adding new job offer job_252e5fe12b052f50ea034dd6d67b572d --- .../job_252e5fe12b052f50ea034dd6d67b572d.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 content/job_offers/job_252e5fe12b052f50ea034dd6d67b572d.md diff --git a/content/job_offers/job_252e5fe12b052f50ea034dd6d67b572d.md b/content/job_offers/job_252e5fe12b052f50ea034dd6d67b572d.md new file mode 100644 index 00000000..c9ecd1dc --- /dev/null +++ b/content/job_offers/job_252e5fe12b052f50ea034dd6d67b572d.md @@ -0,0 +1,22 @@ +Title: Testeur de formulaire +Date: 2019-04-04 23:43 +Slug: job_252e5fe12b052f50ea034dd6d67b572d +Category: job +Authors: Matthieu Boileau +Email: matthieu.boileau@math.unistra.fr +Job_Type: Stage +Tags: stage +Template: job_offer +Job_Location: Strasbourg +Job_Duration: Une semaine +Job_Website: https://www.irma.math.unistra.fr +Job_Employer: CNRS +Attachment: + +Programme : +tester les champs +vérifier les notifications +tester la syntaxe markdown <https://calcul.math.cnrs.fr> +Compétences +cliquer sur des boutons +taper au clavier \ No newline at end of file -- GitLab From cda2f51062825abf03543a189a48af0655bba929 Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Thu, 4 Apr 2019 23:52:17 +0200 Subject: [PATCH 24/31] email notification: cleaning test lines --- .gitlab-ci.yml | 3 --- content/job_offers/gitlab_config.py | 3 +-- .../job_0702192bfa0db6000ba32157b863a5a6.md | 22 ---------------- .../job_252e5fe12b052f50ea034dd6d67b572d.md | 22 ---------------- .../job_4175e3e8172f470ee5434ce3a1309f42.md | 26 ------------------- .../job_8d772efed0a69ae9cc692be2fd6a9ab3.md | 22 ---------------- .../job_9db7ed3285261f292ab3d901f58dfb83.md | 22 ---------------- .../job_b161674a75dc54d4bd08925e7a9d5b44.md | 26 ------------------- .../job_f70cfa3e52baa9b6558110b6d1704efc.md | 22 ---------------- utils/notify_job_offer_author.py | 4 +-- 10 files changed, 2 insertions(+), 170 deletions(-) delete mode 100644 content/job_offers/job_0702192bfa0db6000ba32157b863a5a6.md delete mode 100644 content/job_offers/job_252e5fe12b052f50ea034dd6d67b572d.md delete mode 100644 content/job_offers/job_4175e3e8172f470ee5434ce3a1309f42.md delete mode 100644 content/job_offers/job_8d772efed0a69ae9cc692be2fd6a9ab3.md delete mode 100644 content/job_offers/job_9db7ed3285261f292ab3d901f58dfb83.md delete mode 100644 content/job_offers/job_b161674a75dc54d4bd08925e7a9d5b44.md delete mode 100644 content/job_offers/job_f70cfa3e52baa9b6558110b6d1704efc.md diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 510ce161..29fe7057 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,9 +4,6 @@ stages: - deploy - post-deploy -before_script: - - export - deps: stage: deps tags: diff --git a/content/job_offers/gitlab_config.py b/content/job_offers/gitlab_config.py index ffbb8683..37660e2c 100644 --- a/content/job_offers/gitlab_config.py +++ b/content/job_offers/gitlab_config.py @@ -2,8 +2,7 @@ GITLAB_URL = "https://gitlab.math.unistra.fr" GITLAB_TOKEN = "oH9EHD7FU4A8sPHgdoDP" GITLAB_TARGET_ID = 309 # groupe-calcul/website -#GITLAB_TARGET_BRANCH = 'develop' -GITLAB_TARGET_BRANCH = 'dev-boileau' +GITLAB_TARGET_BRANCH = 'develop' GITLAB_SOURCE_ID = 309 # groupe-calcul/website GITLAB_REF_BRANCH = GITLAB_TARGET_BRANCH # Head of the job branch GITLAB_LABELS = ["Offre d'emploi"] diff --git a/content/job_offers/job_0702192bfa0db6000ba32157b863a5a6.md b/content/job_offers/job_0702192bfa0db6000ba32157b863a5a6.md deleted file mode 100644 index fd3cc012..00000000 --- a/content/job_offers/job_0702192bfa0db6000ba32157b863a5a6.md +++ /dev/null @@ -1,22 +0,0 @@ -Title: Testeur de formulaire -Date: 2019-04-04 23:24 -Slug: job_0702192bfa0db6000ba32157b863a5a6 -Category: job -Authors: Matthieu Boileau -Email: matthieu.boileau@math.unistra.fr -Job_Type: Stage -Tags: stage -Template: job_offer -Job_Location: Strasbourg -Job_Duration: Une semaine -Job_Website: https://www.irma.math.unistra.fr -Job_Employer: CNRS -Attachment: - -Programme : -tester les champs -vérifier les notifications -tester la syntaxe markdown <https://calcul.math.cnrs.fr> -Compétences -cliquer sur des boutons -taper au clavier \ No newline at end of file diff --git a/content/job_offers/job_252e5fe12b052f50ea034dd6d67b572d.md b/content/job_offers/job_252e5fe12b052f50ea034dd6d67b572d.md deleted file mode 100644 index c9ecd1dc..00000000 --- a/content/job_offers/job_252e5fe12b052f50ea034dd6d67b572d.md +++ /dev/null @@ -1,22 +0,0 @@ -Title: Testeur de formulaire -Date: 2019-04-04 23:43 -Slug: job_252e5fe12b052f50ea034dd6d67b572d -Category: job -Authors: Matthieu Boileau -Email: matthieu.boileau@math.unistra.fr -Job_Type: Stage -Tags: stage -Template: job_offer -Job_Location: Strasbourg -Job_Duration: Une semaine -Job_Website: https://www.irma.math.unistra.fr -Job_Employer: CNRS -Attachment: - -Programme : -tester les champs -vérifier les notifications -tester la syntaxe markdown <https://calcul.math.cnrs.fr> -Compétences -cliquer sur des boutons -taper au clavier \ No newline at end of file diff --git a/content/job_offers/job_4175e3e8172f470ee5434ce3a1309f42.md b/content/job_offers/job_4175e3e8172f470ee5434ce3a1309f42.md deleted file mode 100644 index cceb96b2..00000000 --- a/content/job_offers/job_4175e3e8172f470ee5434ce3a1309f42.md +++ /dev/null @@ -1,26 +0,0 @@ -Title: Testeur de formulaire -Date: 2019-04-04 22:43 -Slug: job_4175e3e8172f470ee5434ce3a1309f42 -Category: job -Authors: Matthieu Boileau -Email: matthieu.boileau@math.unistra.fr -Job_Type: Stage -Tags: stage -Template: job_offer -Job_Location: Strasbourg -Job_Duration: Une semaine -Job_Website: https://www.irma.math.unistra.fr -Job_Employer: CNRS -Attachment: - -## Programme : - -- tester les champs -- vérifier les notifications -- tester la *syntaxe* **markdown** <https://calcul.math.cnrs.fr> - - -## Compétences - -- cliquer sur des boutons -- taper au clavier diff --git a/content/job_offers/job_8d772efed0a69ae9cc692be2fd6a9ab3.md b/content/job_offers/job_8d772efed0a69ae9cc692be2fd6a9ab3.md deleted file mode 100644 index 362f527b..00000000 --- a/content/job_offers/job_8d772efed0a69ae9cc692be2fd6a9ab3.md +++ /dev/null @@ -1,22 +0,0 @@ -Title: Testeur de formulaire -Date: 2019-04-04 23:29 -Slug: job_8d772efed0a69ae9cc692be2fd6a9ab3 -Category: job -Authors: Matthieu Boileau -Email: matthieu.boileau@math.unistra.fr -Job_Type: Stage -Tags: stage -Template: job_offer -Job_Location: Strasbourg -Job_Duration: Une semaine -Job_Website: https://www.irma.math.unistra.fr -Job_Employer: CNRS -Attachment: - -Programme : -tester les champs -vérifier les notifications -tester la syntaxe markdown <https://calcul.math.cnrs.fr> -Compétences -cliquer sur des boutons -taper au clavier \ No newline at end of file diff --git a/content/job_offers/job_9db7ed3285261f292ab3d901f58dfb83.md b/content/job_offers/job_9db7ed3285261f292ab3d901f58dfb83.md deleted file mode 100644 index 2c94dcbe..00000000 --- a/content/job_offers/job_9db7ed3285261f292ab3d901f58dfb83.md +++ /dev/null @@ -1,22 +0,0 @@ -Title: Testeur de formulaire -Date: 2019-04-04 23:38 -Slug: job_9db7ed3285261f292ab3d901f58dfb83 -Category: job -Authors: Matthieu Boileau -Email: matthieu.boileau@math.unistra.fr -Job_Type: Stage -Tags: stage -Template: job_offer -Job_Location: Strasbourg -Job_Duration: Une semaine -Job_Website: https://www.irma.math.unistra.fr -Job_Employer: CNRS -Attachment: - -Programme : -tester les champs -vérifier les notifications -tester la syntaxe markdown <https://calcul.math.cnrs.fr> -Compétences -cliquer sur des boutons -taper au clavier \ No newline at end of file diff --git a/content/job_offers/job_b161674a75dc54d4bd08925e7a9d5b44.md b/content/job_offers/job_b161674a75dc54d4bd08925e7a9d5b44.md deleted file mode 100644 index 579eb53a..00000000 --- a/content/job_offers/job_b161674a75dc54d4bd08925e7a9d5b44.md +++ /dev/null @@ -1,26 +0,0 @@ -Title: Testeur de formulaire -Date: 2019-04-04 22:50 -Slug: job_b161674a75dc54d4bd08925e7a9d5b44 -Category: job -Authors: Matthieu Boileau -Email: matthieu.boileau@math.unistra.fr -Job_Type: Stage -Tags: stage -Template: job_offer -Job_Location: Strasbourg -Job_Duration: Une semaine -Job_Website: https://www.irma.math.unistra.fr -Job_Employer: CNRS -Attachment: - -## Programme : - -- tester les champs -- vérifier les notifications -- tester la *syntaxe* **markdown** <https://calcul.math.cnrs.fr> - - -## Compétences - -- cliquer sur des boutons -- taper au clavier diff --git a/content/job_offers/job_f70cfa3e52baa9b6558110b6d1704efc.md b/content/job_offers/job_f70cfa3e52baa9b6558110b6d1704efc.md deleted file mode 100644 index 71fd54ce..00000000 --- a/content/job_offers/job_f70cfa3e52baa9b6558110b6d1704efc.md +++ /dev/null @@ -1,22 +0,0 @@ -Title: Testeur de formulaire -Date: 2019-04-04 23:18 -Slug: job_f70cfa3e52baa9b6558110b6d1704efc -Category: job -Authors: Matthieu Boileau -Email: matthieu.boileau@math.unistra.fr -Job_Type: Stage -Tags: stage -Template: job_offer -Job_Location: Strasbourg -Job_Duration: Une semaine -Job_Website: https://www.irma.math.unistra.fr -Job_Employer: CNRS -Attachment: - -Programme : -tester les champs -vérifier les notifications -tester la syntaxe markdown <https://calcul.math.cnrs.fr> -Compétences -cliquer sur des boutons -taper au clavier \ No newline at end of file diff --git a/utils/notify_job_offer_author.py b/utils/notify_job_offer_author.py index 734d6fa7..aa8aa363 100644 --- a/utils/notify_job_offer_author.py +++ b/utils/notify_job_offer_author.py @@ -78,14 +78,12 @@ def send_email(commit_message, password=None, ): print("Authentication error. Please retry.") password = prompt_for_password() - d = {} + d = {} # dict for templating m = re.match("^Merge branch 'job_(.*)' into '(.*)'$", commit_message) job_id = m.group(1) - print("job_id:", job_id) d['JOB_URL'] = "{}/job_{}.html".format(SITEURL, job_id) - print("d['JOB_URL']:", d['JOB_URL']) filename = f"../content/job_offers/job_{job_id}.md" filepath = os.path.join(script_path, filename) -- GitLab From 412f32f17229de50248de1f1e580a7096978d85b Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Fri, 5 Apr 2019 09:02:38 +0200 Subject: [PATCH 25/31] Update notify_job_offer_author.py some reorg + add --job_id argument --- utils/notify_job_offer_author.py | 87 +++++++++++++++----------------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/utils/notify_job_offer_author.py b/utils/notify_job_offer_author.py index aa8aa363..881d6949 100644 --- a/utils/notify_job_offer_author.py +++ b/utils/notify_job_offer_author.py @@ -55,77 +55,72 @@ Sans demande de votre part, elle restera en ligne jusqu'au $DATE_PUB. Cordialement, Le bureau du groupe Calcul. - """) -def send_email(commit_message, password=None, ): +def send_email(commit_title=None, job_id=None, password=None, ): """Send notification email using smtplib""" - def prompt_for_password(): - return getpass.getpass(f"Please type email password for {SENDER_MAIL}: ") + d = {} # dict for templating - if not password: - password = prompt_for_password() + if not job_id: + m = re.match("^Merge branch 'job_(.*)' into '(.*)'$", commit_title) + job_id = m.group(1) - # Connect to SMTP - with smtplib.SMTP_SSL(MAILSERVER) as smtp: - while True: - try: - smtp.login(SENDER_ACCOUNT, password) - break - except smtplib.SMTPAuthenticationError: - print("Authentication error. Please retry.") - password = prompt_for_password() + d['JOB_URL'] = "{}/job_{}.html".format(SITEURL, job_id) - d = {} # dict for templating + filename = f"../content/job_offers/job_{job_id}.md" + filepath = os.path.join(script_path, filename) - m = re.match("^Merge branch 'job_(.*)' into '(.*)'$", commit_message) - job_id = m.group(1) + with open(filepath) as f: + s = f.read() + # TODO: When expire_date will be in job_*.md file + # m = re.search("Date: (.*)$", s, re.MULTILINE) + # date = m.group(1) + # expire_date to format... + m = re.search("Authors: (.*)$", s, re.MULTILINE) + author_name = m.group(1) + m = re.search("Email: (.*)$", s, re.MULTILINE) + author_email = m.group(1) - d['JOB_URL'] = "{}/job_{}.html".format(SITEURL, job_id) + expire_date = datetime.date.today() + datetime.timedelta(days=90) - filename = f"../content/job_offers/job_{job_id}.md" - filepath = os.path.join(script_path, filename) + d['DATE_PUB'] = '{d.day} {d:%B} {d.year}'.format(d=expire_date) + msg = EmailMessage() + msg['Subject'] = SUBJECT + msg['From'] = Address(SENDER_NAME, SENDER_ACCOUNT_DISPLAY, SENDER_DOMAIN) + msg['To'] = author_email + body = TEMPLATE.substitute(d) + msg.set_content(body) - with open(filepath) as f: - s = f.read() - # TODO: When expire_date will be in job_*.md file - # m = re.search("Date: (.*)$", s, re.MULTILINE) - # date = m.group(1) - #expire_date to format... - m = re.search("Authors: (.*)$", s, re.MULTILINE) - author_name = m.group(1) - m = re.search("Email: (.*)$", s, re.MULTILINE) - author_email = m.group(1) - - expire_date = datetime.date.today() + datetime.timedelta(days=90) + if not password: + password = getpass.getpass(f"Please type email password for {SENDER_MAIL}: ") - d['DATE_PUB'] = '{d.day} {d:%B} {d.year}'.format(d=expire_date) - msg = EmailMessage() - msg['Subject'] = SUBJECT - msg['From'] = Address(SENDER_NAME, SENDER_ACCOUNT_DISPLAY, SENDER_DOMAIN) - msg['To'] = author_email - body = TEMPLATE.substitute(d) - msg.set_content(body) + # Connect to SMTP + with smtplib.SMTP_SSL(MAILSERVER) as smtp: + smtp.login(SENDER_ACCOUNT, password) print(f">>> Sending notification to {author_name} <{author_email}>") print(body) - smtp.sendmail(SENDER_MAIL, author_email, msg.as_string()) def main(): """Read CLI to send email""" parser = argparse.ArgumentParser(description="Send email notification to the author of job offer") - parser.add_argument('--commit_message', nargs=1, metavar='commit-message', required=True) + group = parser.add_mutually_exclusive_group(required=True) + group.add_argument('--commit_title', nargs=1, metavar='commit-title', + help='should be "$CI_COMMIT_TITLE" in .gitlab-ci.yml') + group.add_argument('--job_id', nargs=1, metavar='job-id', + help="bf41a2147c42ef38c98a2cc47b244012 for example") parser.add_argument('--password', nargs=1, metavar="account-password", help="password for sender email account") args = parser.parse_args() - if args.password: - send_email(args.commit_message[0], password=args.password[0]) - else: - send_email(args.commit_message[0]) + password = args.password[0] if args.password else None + if args.commit_title: + send_email(commit_title=args.commit_title[0], password=password) + elif args.job_id: + send_email(job_id=args.job_id[0], password=password) if __name__ == '__main__': -- GitLab From b4809c0f3089640276221c6ec70757d2a08d1f40 Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Fri, 5 Apr 2019 10:48:38 +0200 Subject: [PATCH 26/31] Update notify_job_offer_author.py Add list notification --- utils/notify_job_offer_author.py | 166 ++++++++++++++++++++++--------- 1 file changed, 120 insertions(+), 46 deletions(-) diff --git a/utils/notify_job_offer_author.py b/utils/notify_job_offer_author.py index 881d6949..51d0946d 100644 --- a/utils/notify_job_offer_author.py +++ b/utils/notify_job_offer_author.py @@ -19,7 +19,6 @@ from publishconf import SITEURL # Email -SUBJECT = "Votre annonce d'offre d'emploi a été validée" MAILSERVER = 'mailserver.u-strasbg.fr' SENDER_ACCOUNT = 'math-gitlab-incoming' SENDER_MAIL = "calcul-contact@math.cnrs.fr" @@ -28,81 +27,148 @@ SENDER_ACCOUNT_DISPLAY = "calcul-contact" SENDER_DOMAIN = "math.cnrs.fr" -class Bcolors: - """For printing colored output to terminal""" - OKGREEN = '\033[32m' - WARNING = '\033[33m' - FAIL = '\033[31m' - ENDC = '\033[0m' +class Message: + """Abstract class for message""" + + subject = "" + template = Template("") + + def __init__(self, job_id, recipient_email=None): + self.job_id = job_id + self.job_url = "{}/job_{}.html".format(SITEURL, self.job_id) + self.parse_job_offer_file() + self.recipient_email = recipient_email + + def parse_job_offer_file(self): + filename = f"../content/job_offers/job_{self.job_id}.md" + filepath = os.path.join(script_path, filename) + + with open(filepath) as f: + s = f.read() + # TODO: When expire_date will be in job_*.md file + # m = re.search("Date: (.*)$", s, re.MULTILINE) + # date = m.group(1) + # expire_date to format... + m = re.search("Authors: (.*)$", s, re.MULTILINE) + self.author_name = m.group(1).title() + m = re.search("Email: (.*)$", s, re.MULTILINE) + self.author_email = m.group(1) + m = re.search("Job_Type: (.*)$", s, re.MULTILINE) + self.job_type = m.group(1).lower() + m = re.search("Title: (.*)$", s, re.MULTILINE) + self.job_title = m.group(1) + + def get_email_body(self): + """Virtual function""" + pass + + def get_msg(self): + """Get a message object for job_id""" + body = self.get_email_body() + msg = EmailMessage() + msg['Subject'] = self.subject + msg['From'] = Address(SENDER_NAME, SENDER_ACCOUNT_DISPLAY, SENDER_DOMAIN) + msg['To'] = self.recipient_email + + print(f">>> Sending notification to {self.recipient_name} <{self.recipient_email}>") + print(body) + msg.set_content(body) + return msg -STATUS_OK = "{}{:<4}{}".format(Bcolors.OKGREEN, "OK", Bcolors.ENDC) -STATUS_WARN = "{}{:<4}{}".format(Bcolors.WARNING, "Warn", Bcolors.ENDC) -STATUS_KO = "{}{:<4}{}".format(Bcolors.FAIL, "KO", Bcolors.ENDC) +class AuthorMessage(Message): + """A class to notify job offer authors""" -TEMPLATE = Template("""\ + subject = "Votre annonce d'offre d'emploi a été validée" + template = Template("""\ Bonjour, Merci d'avoir déposé une annonce d'offre d'emploi sur le site web du groupe Calcul. Cette annonce a été validée par le bureau du groupe Calcul et vient d'être : - - publiée sur $JOB_URL - diffusée sur la liste calcul@listes.math.cnrs.fr. -Sans demande de votre part, elle restera en ligne jusqu'au $DATE_PUB. +Sans demande de votre part, elle restera en ligne jusqu'au $EXPIRE_DATE. Cordialement, Le bureau du groupe Calcul. """) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) -def send_email(commit_title=None, job_id=None, password=None, ): - """Send notification email using smtplib""" + self.recipient_name = self.author_name + if not self.recipient_email: + self.recipient_email = self.author_email - d = {} # dict for templating + def get_email_body(self): + """Parse job offer md file to build email body""" - if not job_id: - m = re.match("^Merge branch 'job_(.*)' into '(.*)'$", commit_title) - job_id = m.group(1) + 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)} + + body = self.template.substitute(d) - d['JOB_URL'] = "{}/job_{}.html".format(SITEURL, job_id) + return body - filename = f"../content/job_offers/job_{job_id}.md" - filepath = os.path.join(script_path, filename) - with open(filepath) as f: - s = f.read() - # TODO: When expire_date will be in job_*.md file - # m = re.search("Date: (.*)$", s, re.MULTILINE) - # date = m.group(1) - # expire_date to format... - m = re.search("Authors: (.*)$", s, re.MULTILINE) - author_name = m.group(1) - m = re.search("Email: (.*)$", s, re.MULTILINE) - author_email = m.group(1) +class ListMessage(Message): + """A class to notify diffusion list""" - expire_date = datetime.date.today() + datetime.timedelta(days=90) + template = Template("""\ +Bonjour, + +$JOB_AUTHOR vient de publier une offre de $JOB_TYPE concernant le poste intitulé "$JOB_TITLE". + +Vous en retrouverez tous les détails sur $JOB_URL. + +Cordialement, + +Le bureau du groupe Calcul. +""") - d['DATE_PUB'] = '{d.day} {d:%B} {d.year}'.format(d=expire_date) - msg = EmailMessage() - msg['Subject'] = SUBJECT - msg['From'] = Address(SENDER_NAME, SENDER_ACCOUNT_DISPLAY, SENDER_DOMAIN) - msg['To'] = author_email - body = TEMPLATE.substitute(d) - msg.set_content(body) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.recipient_name = "Groupe Calcul" + if not self.recipient_email: + self.recipient_email = "bureau.calcul@services.cnrs.fr" + self.subject = "Proposition de {}".format(self.job_type) + + 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} + + body = self.template.substitute(d) + + return body + + +def send_email(commit_title=None, job_id=None, password=None, notifier=None, recipient_email=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) + msg = message.get_msg() if not password: password = getpass.getpass(f"Please type email password for {SENDER_MAIL}: ") # Connect to SMTP with smtplib.SMTP_SSL(MAILSERVER) as smtp: - smtp.login(SENDER_ACCOUNT, password) - print(f">>> Sending notification to {author_name} <{author_email}>") - print(body) - smtp.sendmail(SENDER_MAIL, author_email, msg.as_string()) + smtp.sendmail(SENDER_MAIL, msg['To'], msg.as_string()) def main(): @@ -114,13 +180,21 @@ def main(): group.add_argument('--job_id', nargs=1, metavar='job-id', help="bf41a2147c42ef38c98a2cc47b244012 for example") parser.add_argument('--password', nargs=1, metavar="account-password", help="password for sender email account") + parser.add_argument('--notifier', nargs=1, metavar="notifier-type", required=True, choices=("author", "list"), + help="Type for notifying message") + parser.add_argument('--recipient_email', nargs=1, metavar="recipent-email-address", + help="Override default (author or list address)") 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 if args.commit_title: - send_email(commit_title=args.commit_title[0], password=password) + send_email(commit_title=args.commit_title[0], password=password, notifier=notifier[args.notifier[0]], + recipient_email=recipient_email) elif args.job_id: - send_email(job_id=args.job_id[0], password=password) + send_email(job_id=args.job_id[0], password=password, notifier=notifier[args.notifier[0]], + recipient_email=recipient_email) if __name__ == '__main__': -- GitLab From d85b144b89c9a9cab0d3e1bc5d86dc609ff0efe3 Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Fri, 5 Apr 2019 10:49:44 +0200 Subject: [PATCH 27/31] Rename notify_job_offer script --- .gitlab-ci.yml | 2 +- utils/{notify_job_offer_author.py => notify_job_offer.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename utils/{notify_job_offer_author.py => notify_job_offer.py} (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 29fe7057..b48dc0d4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -87,4 +87,4 @@ notify-job-offer-author: variables: - $CI_COMMIT_TITLE =~ /^Merge branch 'job_.*$/ script: - - python3 utils/notify_job_offer_author.py --commit_message "$CI_COMMIT_TITLE" --password $SENDER_PASSWORD + - python3 utils/notify_job_offer.py --commit_message "$CI_COMMIT_TITLE" --password $SENDER_PASSWORD diff --git a/utils/notify_job_offer_author.py b/utils/notify_job_offer.py similarity index 100% rename from utils/notify_job_offer_author.py rename to utils/notify_job_offer.py -- GitLab From bc60367adeb20e6ead02902b55c2b298c19ff74d Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Fri, 5 Apr 2019 10:56:03 +0200 Subject: [PATCH 28/31] job_offer: notify both author and calcul@listes.math.cnrs.fr override calcul@listes.math.cnrs.fr with $GITLAB_USER_EMAIL for the moment... --- .gitlab-ci.yml | 4 +++- utils/notify_job_offer.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b48dc0d4..266aaef1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -87,4 +87,6 @@ notify-job-offer-author: variables: - $CI_COMMIT_TITLE =~ /^Merge branch 'job_.*$/ script: - - python3 utils/notify_job_offer.py --commit_message "$CI_COMMIT_TITLE" --password $SENDER_PASSWORD + - 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 + diff --git a/utils/notify_job_offer.py b/utils/notify_job_offer.py index 51d0946d..5c94439e 100644 --- a/utils/notify_job_offer.py +++ b/utils/notify_job_offer.py @@ -136,7 +136,7 @@ Le bureau du groupe Calcul. self.recipient_name = "Groupe Calcul" if not self.recipient_email: - self.recipient_email = "bureau.calcul@services.cnrs.fr" + self.recipient_email = "calcul@listes.math.cnrs.fr" self.subject = "Proposition de {}".format(self.job_type) def get_email_body(self): -- GitLab From 3a5f0e1846361c0378667fb47026729658842d2d Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Fri, 5 Apr 2019 11:00:11 +0200 Subject: [PATCH 29/31] Update notify_job_offer.py use bureau.calcul@services.cnrs.fr instead of calcul@listes.math.cnrs.fr for testing... --- utils/notify_job_offer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/notify_job_offer.py b/utils/notify_job_offer.py index 5c94439e..51d0946d 100644 --- a/utils/notify_job_offer.py +++ b/utils/notify_job_offer.py @@ -136,7 +136,7 @@ Le bureau du groupe Calcul. self.recipient_name = "Groupe Calcul" if not self.recipient_email: - self.recipient_email = "calcul@listes.math.cnrs.fr" + self.recipient_email = "bureau.calcul@services.cnrs.fr" self.subject = "Proposition de {}".format(self.job_type) def get_email_body(self): -- GitLab From c30714da98c6126e3b844e2d3541c724934be1a8 Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Fri, 5 Apr 2019 14:08:30 +0200 Subject: [PATCH 30/31] job_offer: update signature for notification emails Super Dupont, pour le groupe Calcul --- .gitlab-ci.yml | 4 ++-- utils/notify_job_offer.py | 41 ++++++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 266aaef1..3dd937e7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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" diff --git a/utils/notify_job_offer.py b/utils/notify_job_offer.py index 51d0946d..e922a8a1 100644 --- a/utils/notify_job_offer.py +++ b/utils/notify_job_offer.py @@ -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__': -- GitLab From 482fe711e927cc48536b3c870c211253ab6fadc7 Mon Sep 17 00:00:00 2001 From: Matthieu Boileau Date: Sat, 6 Apr 2019 12:47:05 +0200 Subject: [PATCH 31/31] =?UTF-8?q?#119=20:=20ajout=20de=20la=20cat=C3=A9gor?= =?UTF-8?q?ie=20dans=20les=20r=C3=A9sultats=20de=20recherche?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/tipue_search/tipue_search.py | 15 +++++++++++++++ themes/calcul/static/css/style.css | 14 ++++++++++++++ themes/calcul/templates/base.html | 1 + 3 files changed, 30 insertions(+) diff --git a/plugins/tipue_search/tipue_search.py b/plugins/tipue_search/tipue_search.py index 11e32612..3bf81877 100644 --- a/plugins/tipue_search/tipue_search.py +++ b/plugins/tipue_search/tipue_search.py @@ -32,6 +32,7 @@ class Tipue_Search_JSON_Generator(object): self.siteurl = settings.get('SITEURL') self.relative_urls = settings.get('RELATIVE_URLS') self.tpages = settings.get('TEMPLATE_PAGES') + self.category_text = settings.get('CIRCLES') # job -> Offres d'emploi, formations -> Nos formations, etc. self.output_path = output_path self.json_nodes = [] @@ -49,6 +50,19 @@ class Tipue_Search_JSON_Generator(object): page_text = ' '.join(page_text.split()) page_category = page.category.name if getattr(page, 'category', 'None') != 'None' else '' + if page_category in self.category_text: + # Create a category button + category_html = """\ + +
+
+ {category_text} +
+
+ """.format(site_url=self.siteurl, page_category=page_category, + category_text=self.category_text[page_category]) + else: + category_html = '' page_url = '.' if page.url: @@ -57,6 +71,7 @@ class Tipue_Search_JSON_Generator(object): node = {'title': page_title, 'text': page_text, 'tags': page_category, + 'note': category_html, 'url': page_url, 'loc': page_url} # changed from 'url' following http://blog.siphos.be/2015/08/updates-on-my-pelican-adventure/ (an update to Pelican made it not work, because the update (e.g., in the theme folder, static/tipuesearch/tipuesearch.js is looking for the 'loc' attribute. diff --git a/themes/calcul/static/css/style.css b/themes/calcul/static/css/style.css index 93ecb5f3..d8741b31 100644 --- a/themes/calcul/static/css/style.css +++ b/themes/calcul/static/css/style.css @@ -1055,3 +1055,17 @@ a.year-toc { background: #252525; color: #ccc; } + +.search-btn.btn-white { + color: black; + background-color: white; + border-radius: 0px; + font-size: 13px; + font-family: 'Roboto'; + font-weight: 500; + line-height: 10px; +} + +.search-btn span { + font-size: 12px; +} \ No newline at end of file diff --git a/themes/calcul/templates/base.html b/themes/calcul/templates/base.html index a853bd7e..82ea3054 100644 --- a/themes/calcul/templates/base.html +++ b/themes/calcul/templates/base.html @@ -146,6 +146,7 @@ {% endif %} 'show': 10, 'newWindow': false, + 'wholeWords': false, {# I cannot place following statements in the conditionals above because then Tipue Search fails to work. Possibly a bug in Tipue Search. #} {% if not 'tipue_search' in PLUGINS %} 'liveDescription': '.article-content' -- GitLab