Skip to content

Commit 03e3af6

Browse files
authored
Setup megalinter conf and fix files (#26)
* Setup megalinter conf and fix files * Disable flake8 * cleanup readme * Disable kics * [MegaLinter] Apply linters fixes --------- Co-authored-by: RelativeSure <[email protected]>
1 parent 936d19b commit 03e3af6

15 files changed

+145
-128
lines changed

.github/workflows/files-changed.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
shell: bash
4141
env:
4242
WEBHOOK: ${{ secrets.WEBHOOK_URL }}
43-
run: ./scripts/copr_webhook.sh $WEBHOOK ${{ github.sha }}
43+
run: ./scripts/copr_webhook.sh "$WEBHOOK" "${{ github.sha }}"
4444

4545
update-readme:
4646
runs-on: ubuntu-latest

.github/workflows/update.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: Update spec files
22
on:
33
workflow_dispatch:
4-
4+
55
schedule:
66
# Runs at 12:00am UTC -> 5:00pm PDT
7-
- cron: '0 0 * * *'
7+
- cron: "0 0 * * *"
88

99
permissions:
1010
# Needs to write to this repo
@@ -14,15 +14,15 @@ jobs:
1414
update:
1515
name: update
1616
runs-on: ubuntu-latest
17-
17+
1818
steps:
1919
- uses: actions/checkout@v4
20-
20+
2121
- uses: actions/setup-python@v5
2222
with:
23-
python-version: '3.12' # Need python version for cache
24-
cache: 'pip' # caching pip dependencies
25-
23+
python-version: "3.12" # Need python version for cache
24+
cache: "pip" # caching pip dependencies
25+
2626
- name: Cache GraphQL API IDs
2727
uses: actions/cache@v4
2828
with:
@@ -35,15 +35,15 @@ jobs:
3535
# Make sure even if the specs change it grabs the old cache
3636
# to start from! Entries are never invalidated, only added
3737
restore-keys: graphql-ids
38-
38+
3939
- name: Install dependencies
4040
run: pip install -r requirements.txt
41-
41+
4242
- name: Set git user to github-actions[bot]
4343
run: |
4444
git config --local user.name "github-actions[bot]"
4545
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
46-
46+
4747
- name: Check and update spec files
4848
run: python -m autocopr.autocopr --verbose --in-place --push specs
4949
env:

.mega-linter.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,22 @@ APPLY_FIXES: all
1414
# default
1515
# ENABLE_LINTERS:
1616

17+
DISABLE_LINTERS:
18+
- PYTHON_PYLINT
19+
- PYTHON_FLAKE8
20+
- REPOSITORY_TRIVY
21+
- REPOSITORY_TRIVY_SBOM
22+
- REPOSITORY_CHECKOV
23+
- REPOSITORY_KICS
24+
1725
DISABLE:
1826
# - COPYPASTE # Uncomment to disable checks of excessive copy-pastes
1927
- SPELL # Comment to enable checks of spelling mistakes
2028

29+
PYTHON_BANDIT_DISABLE_ERRORS: true
30+
2131
SHOW_ELAPSED_TIME: true
2232

2333
FILEIO_REPORTER: false
24-
2534
# Uncomment if you want MegaLinter to detect errors but not block CI to pass
2635
# DISABLE_ERRORS: true

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Autocopr forked repo
22

3-
For any issues or questions related to python scripts, please go to upstream repo.
3+
## For any issues or questions related to python scripts, please go to upstream repo
44

55
<details open>
66

autocopr/autocopr.py

+20-13
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,26 @@ def main():
1515
if args.verbose:
1616
logging.basicConfig(level=logging.INFO)
1717

18-
if (args.push
19-
and subprocess.run(["git", "rev-parse", "--is-inside-work-tree"],
20-
capture_output=True).returncode != 0):
18+
if (
19+
args.push
20+
and subprocess.run(
21+
["git", "rev-parse", "--is-inside-work-tree"], capture_output=True
22+
).returncode
23+
!= 0
24+
):
2125
# We're not in a git repository, exit
2226
logging.error("Cannot use --push when not running in a git repository")
2327
exit(1)
2428

2529
specs = [
26-
parsed for spec in root_dir.glob("**/*.spec")
30+
parsed
31+
for spec in root_dir.glob("**/*.spec")
2732
if (parsed := autocopr.specdata.parse_spec(spec)) is not None
2833
]
2934

3035
latest_vers = autocopr.latestver.get_latest_versions(
31-
specs, args.github_token, root_dir / "graphql_id_cache.json")
36+
specs, args.github_token, root_dir / "graphql_id_cache.json"
37+
)
3238

3339
update_summary = [f"{'Name':15}\t{'Old Version':8}\tNew Version"]
3440

@@ -39,21 +45,22 @@ def main():
3945
]
4046

4147
if not args.dry_run:
42-
for (spec, latest) in latest_vers:
48+
for spec, latest in latest_vers:
4349
if spec.version != latest.ver:
44-
autocopr.update.update_version(spec,
45-
latest,
46-
inplace=args.in_place,
47-
push=args.push)
50+
autocopr.update.update_version(
51+
spec, latest, inplace=args.in_place, push=args.push
52+
)
4853

4954
print("\n".join(update_summary))
5055

5156
if args.dry_run:
5257
print("To update the spec files, run again without the dry-run flag.")
5358
elif not args.in_place:
54-
print("If any specs were updated, the original spec files now have a "
55-
".bk suffix, and the spec files are updated with the newest "
56-
"version.")
59+
print(
60+
"If any specs were updated, the original spec files now have a "
61+
".bk suffix, and the spec files are updated with the newest "
62+
"version."
63+
)
5764
else:
5865
print("Any updates have been applied to the spec files.")
5966

autocopr/cli.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ def create_parser() -> argparse.ArgumentParser:
66
"""Initializes the cli parser."""
77

88
parser = argparse.ArgumentParser(
9-
description="Update versions in RPM Spec files and prepare commits.")
9+
description="Update versions in RPM Spec files and prepare commits."
10+
)
1011
parser.add_argument(
1112
"-p",
1213
"--push",
@@ -35,8 +36,11 @@ def create_parser() -> argparse.ArgumentParser:
3536
parser.add_argument(
3637
"--github-token",
3738
default=os.environ.get("GITHUB_TOKEN"),
38-
help=("Github token to use to access the GraphQL API. "
39-
"Defaults to GITHUB_TOKEN environment variable if not set."))
39+
help=(
40+
"Github token to use to access the GraphQL API. "
41+
"Defaults to GITHUB_TOKEN environment variable if not set."
42+
),
43+
)
4044
parser.add_argument(
4145
"directory",
4246
nargs="?",

autocopr/latestver.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,46 @@
22
from pathlib import Path
33
from typing import Optional
44

5-
import requests
6-
75
import githubapi.graphql
86
import githubapi.rest
7+
import requests
98
from autocopr.specdata import SpecData
109
from githubapi.latest import Latest
1110

1211

13-
def get_latest_versions(specs: list[SpecData], token: Optional[str],
14-
id_cache: Path) -> list[tuple[SpecData, Latest]]:
12+
def get_latest_versions(
13+
specs: list[SpecData], token: Optional[str], id_cache: Path
14+
) -> list[tuple[SpecData, Latest]]:
1515
"""Given a list of specs, optionally a Github token, and a location to load
1616
and store a cache of GraphQL ids, return a list of SpecData with latest version.
1717
Removes any SpecData that does not have a cooresponding version."""
1818

1919
if token:
2020
logging.info(
2121
"GITHUB_TOKEN environment variable or --github-token flag is set, "
22-
"using GraphQL api")
22+
"using GraphQL api"
23+
)
2324

2425
ownerNames = [spec.ownerName for spec in specs]
2526
latest = githubapi.graphql.latest_versions(ownerNames, token, id_cache)
2627

27-
return [(spec, latest[key]) for spec in specs
28-
if (key := spec.ownerName) in latest]
28+
return [
29+
(spec, latest[key]) for spec in specs if (key := spec.ownerName) in latest
30+
]
2931
else:
3032
logging.warning(
3133
"GITHUB_TOKEN environment variable or --github-token flag is not set, "
32-
"using REST api instead of GraphQL.")
34+
"using REST api instead of GraphQL."
35+
)
3336
logging.warning(
3437
"The REST API requires more connections, gathers more data than is "
3538
"needed, and you are limited to 60 requests per hour without a token."
3639
)
3740

3841
with requests.Session() as s:
39-
return [(spec, latest_ver) for spec in specs
40-
if (latest_ver := githubapi.rest.get_latest_version(
41-
spec.ownerName, s)) is not None]
42+
return [
43+
(spec, latest_ver)
44+
for spec in specs
45+
if (latest_ver := githubapi.rest.get_latest_version(spec.ownerName, s))
46+
is not None
47+
]

autocopr/specdata.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@dataclass(frozen=True)
1313
class SpecData:
1414
"""Data from a parsed spec file."""
15+
1516
ownerName: OwnerName
1617
version: str
1718
loc: Path
@@ -34,24 +35,22 @@ def parse_spec(spec_loc: Path) -> Optional[SpecData]:
3435
for line in spec:
3536
# Assumes Version and URL are only defined once in the file!
3637
# If there are duplicate definitions, behavior is undefined!
37-
if (name_match := re.search(RegexConstants.name_pat,
38-
line)) is not None:
38+
if (name_match := re.search(RegexConstants.name_pat, line)) is not None:
3939
logging.info(f'Got name from: "{line.rstrip()}"')
4040
name = name_match.group(1)
41-
elif (ver_match := re.search(RegexConstants.version_pat,
42-
line)) is not None:
41+
elif (ver_match := re.search(RegexConstants.version_pat, line)) is not None:
4342
logging.info(f'Got version from: "{line.rstrip()}"')
4443
version = ver_match.group(1)
45-
elif (url_match := re.search(RegexConstants.url_pat,
46-
line)) is not None:
44+
elif (url_match := re.search(RegexConstants.url_pat, line)) is not None:
4745
logging.info(f'Got url from: "{line.rstrip()}"')
4846
# Remove any trailing slashes, we don't them for future API calls
49-
url = urllib.parse.urlparse(url_match.group(1).rstrip('/'))
47+
url = urllib.parse.urlparse(url_match.group(1).rstrip("/"))
5048
if url.netloc != "github.com":
5149
logging.warning(
5250
f"{spec_loc} is hosted on {url.netloc} "
5351
"but this script only checks projects from github, "
54-
"skipping this file")
52+
"skipping this file"
53+
)
5554
return None
5655

5756
if name is not None and version is not None and url is not None:

autocopr/update.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@
77
from githubapi.latest import Latest
88

99

10-
def update_version(spec: SpecData,
11-
latest: Latest,
12-
inplace: bool = False,
13-
push: bool = False):
10+
def update_version(
11+
spec: SpecData, latest: Latest, inplace: bool = False, push: bool = False
12+
):
1413
"""Given the location of a spec file, the latest version, and the name of
1514
the package, update the version in the spec and make a commit with the
1615
cooresponding COPR tag."""
1716

1817
logging.info(f"Updating {spec.name} file to {latest.ver}...")
19-
spec_loc_backup = spec.loc.rename(
20-
spec.loc.with_suffix(spec.loc.suffix + ".bak"))
18+
spec_loc_backup = spec.loc.rename(spec.loc.with_suffix(spec.loc.suffix + ".bak"))
2119

22-
with (open(spec.loc, "w") as new_spec, open(spec_loc_backup) as old_spec):
20+
with open(spec.loc, "w") as new_spec, open(spec_loc_backup) as old_spec:
2321
# Again, assumes that Version and Release are only defined once!
2422
for line in old_spec:
2523
if re.match(RegexConstants.version_pat, line):
@@ -43,9 +41,9 @@ def update_version(spec: SpecData,
4341
subprocess.run(["git", "commit", "-m", commit_msg])
4442
# Have to make an annotated tag for github to recognize it
4543
# message is the same as the commit message
46-
subprocess.run([
47-
"git", "tag", "-a", "-m", commit_msg, f"{spec.name}-{latest.ver}"
48-
])
44+
subprocess.run(
45+
["git", "tag", "-a", "-m", commit_msg, f"{spec.name}-{latest.ver}"]
46+
)
4947
# The github webhooks won't fire if 3+ tags are made at once, to be
5048
# defensive push each tag by itself
5149
subprocess.run(["git", "push", "--follow-tags"])

0 commit comments

Comments
 (0)