Module: tools Branch: master Commit: 25a13879d60b4d9c510942e13311d481c25d5b08 URL: https://source.winehq.org/git/tools.git/?a=commit;h=25a13879d60b4d9c510942e1...
Author: Jeremy White jwhite@codeweavers.com Date: Thu Apr 28 06:45:57 2022 -0500
Add a READ_ONLY flag to help with testing.
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
gitlab/gitlab-to-mail/example.cfg | 4 ++++ gitlab/gitlab-to-mail/gitlabtomail.py | 19 ++++++++++++------- gitlab/gitlab-to-mail/util.py | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/gitlab/gitlab-to-mail/example.cfg b/gitlab/gitlab-to-mail/example.cfg index 19e877c..a0fc59d 100644 --- a/gitlab/gitlab-to-mail/example.cfg +++ b/gitlab/gitlab-to-mail/example.cfg @@ -6,6 +6,10 @@ DATABASE= "/home/wine/example/db_example.sqlite" # if True mails are dumped to mail_dump mbox file instead of being sent out DEBUG = False
+# If True, no writes are done to the database. This allows a particular +# condition to be run again and again +#READ_ONLY = False + # https://docs.gitlab.com/ce/user/profile/personal_access_tokens.html with API access GITLAB_TOKEN = "secret" GITLAB_URL = "https://gitlab.example.com/" diff --git a/gitlab/gitlab-to-mail/gitlabtomail.py b/gitlab/gitlab-to-mail/gitlabtomail.py index dfe72e2..19eafa3 100755 --- a/gitlab/gitlab-to-mail/gitlabtomail.py +++ b/gitlab/gitlab-to-mail/gitlabtomail.py @@ -540,7 +540,8 @@ def main(): last_mr_updated_at = db.get_last_mr_updated_at() if not last_mr_updated_at: last_mr_updated_at = datetime.datetime.now() - datetime.timedelta(days=settings.INITIAL_BACKLOG_DAYS) - db.set_last_mr_updated_at(last_mr_updated_at) + if not settings.READ_ONLY: + db.set_last_mr_updated_at(last_mr_updated_at)
for mr in fetch_recently_updated_mrs(last_mr_updated_at): iid = mr['iid'] @@ -575,7 +576,8 @@ def main():
if not error_in_notes(iid, error): post_note(iid, error) - db.set_last_mr_updated_at(updated_at) + if not settings.READ_ONLY: + db.set_last_mr_updated_at(updated_at) continue
date = get_mr_version_date(versions, version) @@ -599,15 +601,17 @@ def main(): mail['References'] = create_reference(mr['id'], gitlab_hostname) log(f"MR{iid}v{version} - sent email") send_email(mail) - db.mark_mr_version_processed(iid, version) - db.set_last_mr_updated_at(updated_at) + if not settings.READ_ONLY: + db.mark_mr_version_processed(iid, version) + db.set_last_mr_updated_at(updated_at) else: log(f"MR{iid}v{version} - skipping, already processed")
date = db.get_last_event_date() if not date: date = (datetime.datetime.now() - datetime.timedelta(days=settings.INITIAL_BACKLOG_DAYS)).date() - db.set_last_event_date(date) + if not settings.READ_ONLY: + db.set_last_event_date(date)
date = date - datetime.timedelta(days=1) last_event_id = db.get_last_event_id() @@ -624,8 +628,9 @@ def main(): log(f"sending email {mail['Subject']}") send_email(mail)
- db.set_last_event_date(parse_gitlab_datetime(event['created_at']).date()) - db.set_last_event_id(event['id']) + if not settings.READ_ONLY: + db.set_last_event_date(parse_gitlab_datetime(event['created_at']).date()) + db.set_last_event_id(event['id'])
if __name__ == "__main__": diff --git a/gitlab/gitlab-to-mail/util.py b/gitlab/gitlab-to-mail/util.py index e37ead8..aef43c6 100644 --- a/gitlab/gitlab-to-mail/util.py +++ b/gitlab/gitlab-to-mail/util.py @@ -31,7 +31,7 @@ class Settings: else: self.__dict__[s] = None
- for s in ['DEBUG']: + for s in ['DEBUG', 'READ_ONLY']: if s in self.cp['settings']: self.__dict__[s] = self.cp['settings'].getboolean(s) else: