Skip to content

Commit dd2677c

Browse files
Merge branch 'main' into pylint
2 parents 328ef4d + f9c249e commit dd2677c

File tree

5 files changed

+89
-10
lines changed

5 files changed

+89
-10
lines changed

.github/workflows/auto-label.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: "Automatically mark PRs to sync"
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
8+
jobs:
9+
labeler:
10+
if: github.event.pull_request.user.type != 'Bot'
11+
permissions:
12+
pull-requests: write
13+
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Add "sync" label to PR
17+
run: gh pr edit "$PR_URL" --add-label sync --repo "$PR_REPO"
18+
env:
19+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
PR_URL: ${{ github.event.pull_request.html_url }}
21+
PR_REPO: ${{ github.repository }}
22+
23+
- name: Comment on PR to explain sync label
24+
run: gh pr comment "$PR_URL" --body "This pull request has been marked to **automatically sync** to its base branch. You can **disable** this behavior by removing the `sync` label." --repo "$PR_REPO"
25+
env:
26+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
PR_URL: ${{ github.event.pull_request.html_url }}
28+
PR_REPO: ${{ github.repository }}

.github/workflows/autoupdate.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: pr-auto-update
2+
on:
3+
push: {}
4+
5+
jobs:
6+
pr-auto-update:
7+
name: Automatic PR Updater
8+
runs-on: ubuntu-latest
9+
permissions:
10+
pull-requests: write
11+
contents: write
12+
steps:
13+
- uses: CSSUoB/pr-auto-updater@v2.2.2
14+
env:
15+
GITHUB_TOKEN: '${{ secrets.PR_AUTO_UPDATE_TOKEN }}'
16+
PR_FILTER: 'labelled'
17+
PR_LABELS: 'sync'
18+
MERGE_CONFLICT_ACTION: 'label'
19+
MERGE_CONFLICT_LABEL: 'conflict'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: "Automatically enable auto-merge on PRs"
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- ready_for_review
8+
branches:
9+
- main
10+
11+
jobs:
12+
enable-automerge:
13+
if: github.event.pull_request.draft == false
14+
permissions:
15+
pull-requests: write
16+
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Enable auto-merge for the PR
20+
run: gh pr merge "$PR_URL" --auto --squash
21+
env:
22+
GH_TOKEN: ${{ secrets.PR_AUTO_UPDATE_TOKEN }}
23+
PR_URL: ${{ github.event.pull_request.html_url }}

css-reports/app.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
from flask import Flask, request, send_file, jsonify, redirect
2-
from report import get_product_customisations
1+
"""Module to handle the incoming http requests and generate reports."""
2+
33
from datetime import datetime
44
import os
55
import re
66

7+
from flask import Flask, request, send_file, jsonify, redirect
8+
from report import get_product_customisations
9+
10+
711
app = Flask("css-reports")
812

913

1014
@app.route("/")
1115
def hello():
16+
"""Redirect to the main website if no specific route is requested."""
1217
return redirect("https://cssbham.com", code=302)
1318

1419

1520
@app.errorhandler(404)
1621
def page_not_found(e: Exception | int):
22+
"""Handle 404 errors by redirecting to the main website."""
1723
print(e)
1824
return redirect("https://cssbham.com", code=302)
1925

2026

2127
@app.route("/customisation_report", methods=["GET"])
2228
async def fetch_customisation_report():
29+
"""Fetch the report based on query parameters."""
2330
# Retrieve query parameters
2431
auth_cookie: str | None = request.args.get("auth_cookie")
2532
organisation_id: str | None = request.args.get("organisation_id")

css-reports/report.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""Python script to fetch a customisation report from the Guild website."""
22

3+
import re
4+
from datetime import datetime
5+
36
from typing import Final, Mapping, TYPE_CHECKING
47
import aiohttp
58
import bs4
69
from bs4 import BeautifulSoup
7-
import re
8-
from datetime import datetime
10+
911

1012
if TYPE_CHECKING:
1113
from http.cookies import Morsel
@@ -83,9 +85,8 @@ async def fetch_report_url_and_cookies(
8385
SALES_REPORTS_URL: Final[str] = (
8486
f"https://www.guildofstudents.com/organisation/salesreports/{org_id}/"
8587
)
86-
data_fields, cookies = await get_msl_context(
87-
url=SALES_REPORTS_URL, auth_cookie=auth_cookie
88-
)
88+
89+
data_fields, cookies = await get_msl_context(url=SALES_REPORTS_URL, auth_cookie=auth_cookie)
8990

9091
form_data: dict[str, str] = {
9192
SALES_FROM_DATE_KEY: from_date.strftime("%d/%m/%Y"),
@@ -105,9 +106,10 @@ async def fetch_report_url_and_cookies(
105106
headers=BASE_HEADERS,
106107
cookies=cookies,
107108
)
108-
109-
async with (session_v2, session_v2.post(url=SALES_REPORTS_URL, data=data_fields) as http_response): # noqa: E501
110-
109+
async with (
110+
session_v2,
111+
session_v2.post(url=SALES_REPORTS_URL, data=data_fields) as http_response
112+
):
111113
if http_response.status != 200:
112114
print("Returned a non 200 status code!!")
113115
print(http_response)

0 commit comments

Comments
 (0)