Skip to content

Commit 07597dc

Browse files
authored
Merge branch 'master' into merge
2 parents 613e33b + 8fb95f5 commit 07597dc

File tree

9 files changed

+106
-55
lines changed

9 files changed

+106
-55
lines changed

.github/workflows/main.yml

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ name: CI
22

33
on: [push]
44

5+
concurrency:
6+
group: ${{ github.workflow }}${{ github.ref_name != github.event.repository.default_branch && github.ref || github.run_id }}
7+
cancel-in-progress: ${{ github.ref_name != github.event.repository.default_branch }}
8+
59
jobs:
610
test:
7-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-latest
812
strategy:
913
matrix:
1014
python-version: [3.12, 3.9]
@@ -13,32 +17,32 @@ jobs:
1317
IS_COVERAGE_ALLOWED: ${{ secrets.CODACY_PROJECT_TOKEN != '' }}
1418
IS_MASTER_BRANCH: ${{ github.ref == 'refs/heads/master' }}
1519
steps:
16-
- uses: actions/checkout@v2
17-
- name: Set up Python
18-
uses: actions/setup-python@v2
19-
with:
20-
python-version: ${{ matrix.python-version }}
21-
- name: Install poetry
22-
uses: abatilo/actions-poetry@v2.0.0
23-
with:
24-
poetry-version: ${{ matrix.poetry-version }}
25-
- name: Install pip dependencies
26-
run: poetry install
27-
- name: Run tests
28-
run: poetry run pytest --cov-report xml --cov=autopr test/ -v
20+
- uses: actions/checkout@v2
21+
- name: Set up Python
22+
uses: actions/setup-python@v2
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
- name: Install poetry
26+
uses: abatilo/actions-poetry@v2.0.0
27+
with:
28+
poetry-version: ${{ matrix.poetry-version }}
29+
- name: Install pip dependencies
30+
run: poetry install
31+
- name: Run tests
32+
run: poetry run pytest --cov-report xml --cov=autopr test/ -v
2933
lint:
30-
runs-on: ubuntu-20.04
34+
runs-on: ubuntu-latest
3135
steps:
32-
- uses: actions/checkout@v2
33-
- name: Set up Python
34-
uses: actions/setup-python@v2
35-
with:
36-
python-version: 3.9
37-
- name: Install poetry
38-
uses: abatilo/actions-poetry@v2.0.0
39-
with:
40-
poetry-version: 1.3.1
41-
- name: Install pip dependencies
42-
run: poetry install
43-
- name: Run pre-commit
44-
run: poetry run pre-commit run --all-files --show-diff-on-failure
36+
- uses: actions/checkout@v2
37+
- name: Set up Python
38+
uses: actions/setup-python@v2
39+
with:
40+
python-version: 3.9
41+
- name: Install poetry
42+
uses: abatilo/actions-poetry@v2.0.0
43+
with:
44+
poetry-version: 1.3.1
45+
- name: Install pip dependencies
46+
run: poetry install
47+
- name: Run pre-commit
48+
run: poetry run pre-commit run --all-files --show-diff-on-failure

.github/workflows/publish.yml

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,29 @@ on:
44
release:
55
types: [published]
66

7+
concurrency:
8+
group: ${{ github.workflow }}${{ github.ref_name != github.event.repository.default_branch && github.ref || github.run_id }}
9+
cancel-in-progress: ${{ github.ref_name != github.event.repository.default_branch }}
10+
711
jobs:
812
publish:
9-
runs-on: ubuntu-20.04
13+
runs-on: ubuntu-latest
1014
steps:
11-
- uses: actions/checkout@master
12-
- uses: actions/setup-python@v1
13-
with:
14-
python-version: 3.9
15-
- name: Install poetry
16-
uses: abatilo/actions-poetry@v2.0.0
17-
with:
18-
poetry-version: 1.3.1
19-
- name: Install pip dependencies
20-
run: poetry install
21-
- name: Package
22-
run: |
23-
poetry build
24-
- name: Publish to PyPI
25-
uses: pypa/gh-action-pypi-publish@v1.8.8
26-
with:
27-
user: __token__
28-
password: ${{ secrets.pypi_token }}
15+
- uses: actions/checkout@master
16+
- uses: actions/setup-python@v1
17+
with:
18+
python-version: 3.9
19+
- name: Install poetry
20+
uses: abatilo/actions-poetry@v2.0.0
21+
with:
22+
poetry-version: 1.3.1
23+
- name: Install pip dependencies
24+
run: poetry install
25+
- name: Package
26+
run: |
27+
poetry build
28+
- name: Publish to PyPI
29+
uses: pypa/gh-action-pypi-publish@v1.8.8
30+
with:
31+
user: __token__
32+
password: ${{ secrets.pypi_token }}

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Changelog
22

3-
## 1.0.8
3+
## 1.0.9
4+
45
- Add `merge` command
6+
- Add `--api-key` flag to `auto-pr run` command
7+
- Allows you to pass the API key as a flag (or as the env APR_API_KEY variable) instead of storing
8+
it in the configuration file
59

610
## 1.0.7
711
- Add `--exclude-missing` when running `auto-pr status`

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ update_command:
5959
- my-file
6060
```
6161
62+
If you wish to keep your API Key outside of `config.yaml`, set the env var `APR_API_KEY` with your GitHub Token
63+
6264
### Repositories
6365

6466
You can define the list of repositories to pull and build into the database to update using a list of rules.

autopr/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,18 @@ def test(pull_repos: bool):
197197
default=DEFAULT_PUSH_DELAY,
198198
help="Delay in seconds between pushing changes to repositories",
199199
)
200-
def run(pull_repos: bool, push_delay: Optional[float]):
200+
@click.option(
201+
"--api-key",
202+
envvar="APR_API_KEY",
203+
required=False,
204+
hide_input=True,
205+
help="The GitHub API key to use if not statically configured",
206+
)
207+
def run(pull_repos: bool, push_delay: Optional[float], api_key: Optional[str]):
201208
"""Run update logic and create pull requests if changes made"""
202209
cfg = workdir.read_config(WORKDIR)
210+
if api_key is not None:
211+
cfg.credentials.api_key = api_key
203212
db = workdir.read_database(WORKDIR)
204213
_ensure_set_up(cfg, db)
205214
gh = github.create_github_client(cfg.credentials.api_key)

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "auto-pr"
3-
version = "1.0.8"
3+
version = "1.0.9"
44
description = "Perform bulk updates across repositories"
55
license = "Apache-2.0"
66

test/test_run.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import subprocess
22
from pathlib import Path
33
from test.test_utils import (
4+
env_var_token_test_config,
45
init_git_repos,
56
run_cli,
67
simple_test_config,
@@ -43,3 +44,21 @@ def test_create_files(_create_github_client: Mock, tmp_path):
4344
db=db,
4445
)
4546
print(result.output)
47+
48+
49+
@patch("autopr.repo.run_cmd", new=_test_cmd)
50+
@patch("autopr.github.create_github_client")
51+
def test_api_key_env_var(_create_github_client: Mock, monkeypatch, tmp_path):
52+
wd = workdir.WorkDir(Path(tmp_path))
53+
db = simple_test_database()
54+
init_git_repos(wd, db)
55+
result = run_cli(
56+
wd,
57+
["run"],
58+
cfg=env_var_token_test_config(),
59+
env={"APR_API_KEY": "env_var_test"},
60+
db=db,
61+
)
62+
assert (
63+
_create_github_client.call_args_list[0][0][0] == "env_var_test"
64+
), f"wrong api_key used for create_github_client: {_create_github_client.call_args_list}"

test/test_utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def run_cli(
1212
cmd: List[str],
1313
cfg: Optional[config.Config] = None,
1414
db: Optional[database.Database] = None,
15+
env: Optional[dict] = None,
1516
should_fail: bool = False,
1617
) -> Result:
1718
if cfg:
@@ -20,10 +21,11 @@ def run_cli(
2021
workdir.write_database(wd, db)
2122

2223
runner = CliRunner()
24+
env = env or {}
2325
result = runner.invoke(
2426
cli,
2527
cmd,
26-
env={"APR_WORKDIR": f"{wd.location}", "APR_DEBUG": "1"},
28+
env={"APR_WORKDIR": f"{wd.location}", "APR_DEBUG": "1", **env},
2729
catch_exceptions=True,
2830
)
2931
if result.exception is not None:
@@ -96,3 +98,10 @@ def get_repository(
9698
removed=removed,
9799
done=done,
98100
)
101+
102+
103+
def env_var_token_test_config() -> config.Config:
104+
credentials = config.Credentials(api_key="", ssh_key_file="test")
105+
pr = config.PrTemplate()
106+
cmd = ["bash", "-c", "echo 'test' > testfile.txt"]
107+
return config.Config(credentials=credentials, pr=pr, update_command=cmd)

0 commit comments

Comments
 (0)