Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/flask-session-0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarmet authored May 15, 2024
2 parents 963295c + b908588 commit 12a887d
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 38 deletions.
37 changes: 26 additions & 11 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
name: basic tests

on:
pull_request:
branches:
- main
push:
branches:
- 'user/**'
- 'feature/**'
- 'improvement/**'
- 'bugfix/**'
- 'dependabot/**'
- 'w/**'
- 'q/**'
- main

permissions: write-all

Expand All @@ -20,7 +17,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: pip
Expand All @@ -35,14 +32,20 @@ jobs:
- run: tox -e tests-api-mock
- run: tox -e coverage-report
- run: tox -e tests-server
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.3.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: ${{ github.repository }}
flags: unittests,server,api-mock

tests-noqueue:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: pip
Expand All @@ -51,14 +54,20 @@ jobs:
- name: Install tox
run: pip install tox
- run: tox -e tests-noqueue
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.3.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: ${{ github.repository }}
flags: tests-noqueue

all-tests:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: pip
Expand All @@ -67,14 +76,20 @@ jobs:
- name: Install tox
run: pip install tox
- run: tox -e tests
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.3.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: ${{ github.repository }}
flags: all-tests

lint:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: pip
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ settings.yml
.coverage
.pytest_cache/
build/
.env
coverage.xml
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# README

[![codecov](https://codecov.io/gh/scality/bert-e/graph/badge.svg?token=VWEQLKMUN5)](https://codecov.io/gh/scality/bert-e)

Scality's automated branch merging tool.

## User documentation
Expand Down
9 changes: 5 additions & 4 deletions bert_e/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

class BertE_Exception(Exception):
code = -1
status: Literal[None, "in_progress", "queued", "success", "failure"] = None


# base exceptions
class TemplateException(BertE_Exception):
code = -2
template = None
status: Literal[None, "in_progress", "success", "failure"] = None
# whether to re-publish if the message is already in the history
dont_repeat_if_in_history = -1

Expand Down Expand Up @@ -148,7 +148,7 @@ class Conflict(TemplateException):
class ApprovalRequired(TemplateException):
code = 115
template = 'need_approval.md'
status = "in_progress"
status = "queued"


class BuildFailed(TemplateException):
Expand All @@ -160,7 +160,7 @@ class BuildFailed(TemplateException):
class AfterPullRequest(TemplateException):
code = 120
template = 'after_pull_request.md'
status = "in_progress"
status = "queued"


class IntegrationDataCreated(InformationException):
Expand Down Expand Up @@ -265,7 +265,7 @@ class RequestIntegrationBranches(TemplateException):
code = 135
template = "request_integration_branches.md"
# TODO: review if it should be failure.
status = "in_progress"
status = "queued"


class QueueBuildFailedMessage(TemplateException):
Expand Down Expand Up @@ -568,6 +568,7 @@ class NothingToDo(SilentException):

class BuildInProgress(SilentException):
code = 303
status = "in_progress"


class BuildNotStarted(SilentException):
Expand Down
30 changes: 17 additions & 13 deletions bert_e/git_host/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def __init__(self, login: str, password: str, email: str,
self.password = password
self.app_id = app_id
self.installation_id = installation_id
self.private_key = jwk_from_pem(private_key)
self.private_key = jwk_from_pem(private_key.encode('utf-8')) \
if private_key else None
self.email = email
self.org = org
self.base_url = base_url.rstrip('/')
Expand Down Expand Up @@ -832,11 +833,11 @@ def set_bot_status(self, status: str | None, title: str, summary: str):
if status == "success":
conclusion = "success"
status = "completed"
elif status == "in_progress":
conclusion = None
elif status == "failure":
conclusion = "failure"
status = "completed"
else:
conclusion = None

self._add_checkrun(
name='bert-e', status=status, conclusion=conclusion,
Expand All @@ -846,18 +847,21 @@ def set_bot_status(self, status: str | None, title: str, summary: str):
def _add_checkrun(
self, name: str, status: str, conclusion: str | None,
title: str, summary: str):
data = {
'name': name,
'head_sha': self.src_commit,
'status': status,
'output': {
'title': title,
'summary': summary,
},
}
if conclusion is not None:
data['conclusion'] = conclusion
LOG.debug(data)
return CheckRun.create(
client=self.client,
data={
'name': name,
'head_sha': self.src_commit,
'status': status,
'conclusion': conclusion,
'output': {
'title': title,
'summary': summary,
},
},
data=data,
owner=self.repo.owner, repo=self.repo.slug
)

Expand Down
2 changes: 1 addition & 1 deletion bert_e/git_host/github/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class AggregateCheckSuites(GitHubSchema):
class Output(GitHubSchema):
title = fields.Str()
summary = fields.Str()
text = fields.Str()
text = fields.Str(allow_none=True)


class CheckRun(GitHubSchema):
Expand Down
2 changes: 1 addition & 1 deletion bert_e/tests/test_bert_e.py
Original file line number Diff line number Diff line change
Expand Up @@ -4797,7 +4797,7 @@ def test_set_bot_status(self):
pr.src_commit, key="bert-e") == "failure"
self.handle(pr.id, settings=settings, options=["bypass_jira_check"])
assert self.get_build_status(
pr.src_commit, key="bert-e") == "in_progress"
pr.src_commit, key="bert-e") == "queued"
self.handle(pr.id, settings=settings, options=self.bypass_all)


Expand Down
2 changes: 1 addition & 1 deletion bert_e/tests/unit/test_github_app_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def client_app():
serialization.Encoding.PEM,
serialization.PrivateFormat.PKCS8,
serialization.NoEncryption()
),
).decode('utf-8'),
base_url="http://localhost:4010",
accept_header="application/json"
)
Expand Down
4 changes: 2 additions & 2 deletions bert_e/workflow/pr_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def _send_comment(settings, pull_request: AbstractPullRequest, msg: str,
def _send_bot_status(settings, pull_request: AbstractPullRequest,
comment: exceptions.TemplateException):
"""Post the bot status in a pull request."""
if settings.send_bot_status is False:
LOG.debug("Not sending bot status (send_bot_status==False)")
if settings.send_bot_status is False or comment.status is None:
LOG.debug("No need to send bot status")
return
LOG.info(f"Setting bot status to {comment.status} as {comment.title}")
pull_request.set_bot_status(
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ Flask==2.2.3
Flask-Markdown==0.3
Flask-WTF==1.0.1
ItsDangerous==2.1.2
Jinja2==3.1.2
Jinja2==3.1.4
jira==2.0.0
Markdown==2.6.11
marshmallow==3.20.1
MarkupSafe==2.1.2
py-gfm==0.1.4
pytest==7.4.2
PyYAML==6.0
PyYAML==6.0.1
requests==2.28.2
requests-mock==1.10.0
requests-mock==1.12.1
werkzeug==2.2.3
WTForms==3.0.1
jwt==1.3.1
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ commands = flake8 bert_e/
[testenv:utests]
deps =
pip==22.3.1
commands = pytest bert_e/tests/unit/ {posargs}
pytest-cov==5.0.0
commands = pytest bert_e/tests/unit/ --cov=bert_e --cov-report=xml {posargs}

[testenv:tests-api-mock]
deps =
Expand Down Expand Up @@ -80,7 +81,7 @@ setenv =
WEBHOOK_LOGIN = {env:WEBHOOK_LOGIN:'webhook'}
WEBHOOK_PWD = {env:WEBHOOK_PWD:'webhook'}

commands = bert-e-serve -v -f {env:BERT_E_SETTINGS:'settings.yml'}
commands = bert-e-serve -v -f {env:BERT_E_SETTINGS:'settings.yml'} -p 8000

[testenv:tests-githost]
passenv = BERT_E_*
Expand Down

0 comments on commit 12a887d

Please sign in to comment.