Skip to content

Commit f0f76fb

Browse files
committed
Setup megalinter conf and fix files
1 parent 936d19b commit f0f76fb

15 files changed

+160
-145
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

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

17+
DISABLE_LINTERS:
18+
- PYTHON_PYLINT
19+
- REPOSITORY_TRIVY
20+
- REPOSITORY_TRIVY_SBOM
21+
- REPOSITORY_CHECKOV
22+
1723
DISABLE:
1824
# - COPYPASTE # Uncomment to disable checks of excessive copy-pastes
1925
- SPELL # Comment to enable checks of spelling mistakes
2026

27+
PYTHON_BANDIT_DISABLE_ERRORS: true
28+
2129
SHOW_ELAPSED_TIME: true
2230

2331
FILEIO_REPORTER: false
24-
2532
# Uncomment if you want MegaLinter to detect errors but not block CI to pass
2633
# DISABLE_ERRORS: true

README.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,87 @@
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

77
<summary>Status badges on COPR builds</summary>
88

99
### atuin
1010

11-
![atuin status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/atuin/status_image/last_build.png)
11+
![atuin status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/atuin/status_image/last_build.png) # noqa: E501
1212
[Upstream](https://github.com/atuinsh/atuin)
1313

1414
### bottom
1515

16-
![bottom status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/bottom/status_image/last_build.png)
16+
![bottom status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/bottom/status_image/last_build.png) # noqa: E501
1717
[Upstream](https://github.com/ClementTsang/bottom)
1818

1919
### chezmoi
2020

21-
![chezmoi status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/chezmoi/status_image/last_build.png)
21+
![chezmoi status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/chezmoi/status_image/last_build.png) # noqa: E501
2222
[Upstream](https://github.com/twpayne/chezmoi)
2323

2424
### fnm
2525

26-
![fnm status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/fnm/status_image/last_build.png)
26+
![fnm status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/fnm/status_image/last_build.png) # noqa: E501
2727
[Upstream](https://github.com/Schniz/fnm)
2828

2929
### jj
3030

31-
![jj status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/jj/status_image/last_build.png)
31+
![jj status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/jj/status_image/last_build.png) # noqa: E501
3232
[Upstream](https://github.com/martinvonz/jj)
3333

3434
### kubie
3535

36-
![kubie status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/kubie/status_image/last_build.png)
36+
![kubie status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/kubie/status_image/last_build.png) # noqa: E501
3737
[Upstream](https://github.com/sbstp/kubie)
3838

3939
### lazydocker
4040

41-
![lazydocker status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/lazydocker/status_image/last_build.png)
41+
![lazydocker status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/lazydocker/status_image/last_build.png) # noqa: E501
4242
[Upstream](https://github.com/jesseduffield/lazydocker)
4343

4444
### lazygit
4545

46-
![lazygit status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/lazygit/status_image/last_build.png)
46+
![lazygit status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/lazygit/status_image/last_build.png) # noqa: E501
4747
[Upstream](https://github.com/jesseduffield/lazygit)
4848

4949
### lazyjj
5050

51-
![lazyjj status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/lazyjj/status_image/last_build.png)
51+
![lazyjj status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/lazyjj/status_image/last_build.png) # noqa: E501
5252
[Upstream](https://github.com/Cretezy/lazyjj)
5353

5454
### lazynpm
5555

56-
![lazynpm status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/lazynpm/status_image/last_build.png)
56+
![lazynpm status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/lazynpm/status_image/last_build.png) # noqa: E501
5757
[Upstream](https://github.com/jesseduffield/lazynpm)
5858

5959
### mise
6060

61-
![mise status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/mise/status_image/last_build.png)
61+
![mise status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/mise/status_image/last_build.png) # noqa: E501
6262
[Upstream](https://github.com/jdx/mise)
6363

6464
### starship
6565

66-
![starship status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/starship/status_image/last_build.png)
66+
![starship status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/starship/status_image/last_build.png) # noqa: E501
6767
[Upstream](https://github.com/starship/starship)
6868

6969
### superfile
7070

71-
![superfile status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/superfile/status_image/last_build.png)
71+
![superfile status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/superfile/status_image/last_build.png) # noqa: E501
7272
[Upstream](https://github.com/yorukot/superfile)
7373

7474
### usage
7575

76-
![usage status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/usage/status_image/last_build.png)
76+
![usage status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/usage/status_image/last_build.png) # noqa: E501
7777
[Upstream](https://github.com/jdx/usage)
7878

7979
### uv
8080

81-
![uv status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/uv/status_image/last_build.png)
81+
![uv status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/uv/status_image/last_build.png) # noqa: E501
8282
[Upstream](https://github.com/astral-sh/uv)
8383

8484
### zellij
8585

86-
![zellij status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/zellij/status_image/last_build.png)
86+
![zellij status](https://copr.fedorainfracloud.org/coprs/relativesure/all-packages/package/zellij/status_image/last_build.png) # noqa: E501
8787
[Upstream](https://github.com/zellij-org/zellij)

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:

0 commit comments

Comments
 (0)