Page MenuHomeSoftware Heritage

Automate weekly-planning script
ClosedPublic

Authored by ardumont on Jan 25 2022, 4:02 PM.

Details

Summary

This installs the weekly planning report script in pergamon:

  • It's triggered every monday around 8:30 am
  • It creates anonymously a new page initialized (with the default template used for the

weekly planning)

  • Then send an email to the swh-team@inria.fr mailing list

I did not made the script into a template and left the template-id and the hedgedoc
instance hardcoded in the script. Shout out if you want me to do the extra templating.

Related to T3877

Test Plan

octo-diff:

$ $SWH_PUPPET_ENVIRONMENT_HOME/bin/octocatalog-diff --octocatalog-diff-args --no-truncate-details --to staging pergamon
Found host pergamon.softwareheritage.org
...
diff origin/production/pergamon.softwareheritage.org current/pergamon.softwareheritage.org
*******************************************
+ Concat_fragment[profile::cron::weekly-planning-bot] =>
   parameters =>
      "order": "10"
      "tag": "profile::cron::default"
      "target": "profile::cron::default"
      "content": >>>
# Cron snippet weekly-planning-bot
30 6 * * mon nobody chronic /usr/local/bin/weekly-planning-bot
<<<
*******************************************
...
+ File[/usr/local/bin/weekly-planning-bot] =>
   parameters =>
      "ensure": "present"
      "group": "root"
      "mode": "0755"
      "owner": "root"
      "content": >>>
#!/usr/bin/env bash

DEST=swh-team@inria.fr
AUTHOR=swh-team@inria.fr
TEMPLATE_ID="6YKT5osoST-amJQ0MusH2Q"
URL="https://hedgedoc.softwareheritage.org"
DATE=`date +%G-W%V`

# Retrieve the template's content
TEMPLATE=`http -pb "${URL}/${TEMPLATE_ID}/download"`
TEMPLATE=$(echo "$TEMPLATE" | sed -e "s/\$DATE/$DATE/g")

# Create a new page initialized with the template content
RESP=`http -ph POST "${URL}/new" content-type:text/markdown <<< "$TEMPLATE"`
LOCATION=`echo "$RESP" | grep "Location:" | cut -c 11-`

if [ -n "$LOCATION" ] ; then

  /usr/lib/sendmail -t <<EOF
From: Weekly planning bot <$AUTHOR>
To: $DEST
Subject: [Weekly Planning] Week $DATE

Beep boop, I'm a bot.

Here is the pad for the next weekly planning meeting:

    $LOCATION

Please take a few minutes to pre-fill your part.

Remote attendees:

    https://meet.jit.si/EquivalentCoincidencesVentureOnlySwhTeam

Yours faithfully,
--
The Software Heritage weekly bot
EOF

fi
<<<
*******************************************
+ Package[httpie] =>
   parameters =>
      "ensure": "installed"
*******************************************
+ Profile::Cron::D[weekly-planning-bot] =>
   parameters =>
      "command": "chronic /usr/local/bin/weekly-planning-bot"
      "hour": 6
      "minute": 30
      "target": "default"
      "unique_tag": "weekly-planning-bot"
      "user": "nobody"
      "weekday": "mon"
*******************************************
*** End octocatalog-diff on pergamon.softwareheritage.org

Diff Detail

Repository
rSPSITE puppet-swh-site
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Actually send the email instead of just displaying it

ardumont edited the summary of this revision. (Show Details)
vsellier added a subscriber: vsellier.

thanks, just a small inlined remark regarding the httpie package installation

site-modules/profile/manifests/weekly_planning_bot.pp
11–13

maybe you should use ensure_packages to be error proof if httpie is installed by another class

This revision is now accepted and ready to land.Jan 25 2022, 4:28 PM
site-modules/profile/manifests/weekly_planning_bot.pp
11–13

oh yeah, totally!

ardumont edited the summary of this revision. (Show Details)
ardumont edited the test plan for this revision. (Show Details)

Adapt according to review

olasd added inline comments.
data/common/common.yaml
3141–3146

That's UTC, so the mail will arrive pretty late in summer time (10:30 Paris summer time)

site-modules/profile/files/weekly_planning_bot/weekly-planning-bot
16

where's the session stored?

site-modules/profile/manifests/weekly_planning_bot.pp
9–27

Instead of using require you should just chain the resources (which will also avoid missing a require on the script).

Wrap command call with chronic

Adapt what's possible from the last round of review
Thanks!

data/common/common.yaml
3141–3146

good catch, i've cheated a bit with a -2 here so that should cover both utc+{1,2} (or is it -?)

site-modules/profile/files/weekly_planning_bot/weekly-planning-bot
16

In the user's home session

--session SESSION_NAME_OR_PATH

       Create, or reuse and update a session. Within a session, custom headers, auth credential, as well as any cookies sent by the server persist between requests.

       Session files are stored in:

       /home/gaetano/.httpie/sessions/<HOST>/<SESSION_NAME>.json.

But i gather this can simply go away.
As there is no longer authentication and whatnot here.

site-modules/profile/manifests/weekly_planning_bot.pp
9–27
ensure_packages('httpie')
-> file ...

seem to not go well together.

Error: Failed to compile catalog for node pergamon.softwareheritage.org: Evaluation Error: Illegal relationship operand, can not form a relationship with an Undef Value. A Catalog type is required. (file: /tmp/ocd-ipc-20220125-113675-1yq7inz/ocd-builddir-20220125-113677-447t7m/environments/production/site-modules/profile/manifests/weekly_planning_bot.pp, line: 12, column: 3) on node pergamon.softwareheritage.org
data/common/common.yaml
3141–3146

UTC+{1,2} it is indeed.

So that will make it 7:30 am during CET (around now) and 8:30 during CEST.

This revision was automatically updated to reflect the committed changes.
ardumont marked an inline comment as done.