Skip to content

Commit 585690e

Browse files
committed
🐛 handle url not found exception when the github url is not yet ready/does not exist
1 parent b7ec177 commit 585690e

File tree

6 files changed

+58
-27
lines changed

6 files changed

+58
-27
lines changed

.github/workflows/moban-update.yml

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@ jobs:
55
runs-on: ubuntu-latest
66
name: synchronize templates via moban
77
steps:
8-
- uses: actions/checkout@v2
9-
with:
10-
ref: ${{ github.head_ref }}
11-
- name: Set up Python
12-
uses: actions/setup-python@v1
13-
with:
14-
python-version: '3.7'
15-
- name: check changes
16-
run: |
17-
pip install moban gitfs2 pypifs
18-
moban
19-
git status
20-
git diff --exit-code
21-
- name: Auto-commit
22-
if: failure()
23-
uses: docker://cdssnc/auto-commit-github-action
24-
env:
25-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26-
with:
27-
args: This is an auto-commit, updating project meta data, such as changelog.rst, contributors.rst
8+
- uses: actions/checkout@v2
9+
with:
10+
ref: ${{ github.head_ref }}
11+
- name: Set up Python
12+
uses: actions/setup-python@v1
13+
with:
14+
python-version: '3.7'
15+
- name: check changes
16+
run: |
17+
pip install moban gitfs2 pypifs
18+
moban
19+
git status
20+
git diff --exit-code
21+
- name: Auto-commit
22+
if: failure()
23+
uses: docker://cdssnc/auto-commit-github-action
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
with:
27+
args: >-
28+
This is an auto-commit, updating project meta data,
29+
such as changelog.rst, contributors.rst

changelog.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: moban-jinja2-github
22
organisation: moremoban
33
releases:
4+
- changes:
5+
- action: first release
6+
details:
7+
- cope with new born project where github link is not ready. contributors list will be empty.
8+
version: 0.0.2
9+
date: 28.08.2020
410
- changes:
511
- action: first release
612
details:

moban-jinja2-github.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: "moban-jinja2-github"
22
organisation: "moremoban"
33
author: "chfw"
44
5-
company: "chfw"
6-
version: "0.0.1"
7-
current_version: "0.0.1"
8-
release: "0.0.1"
5+
company: "C.W."
6+
version: "0.0.2"
7+
current_version: "0.0.2"
8+
release: "0.0.2"
99
copyright_year: 2020
1010
license: newbsd
1111
dependencies:

moban_jinja2_github/contributors.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
from gease.exceptions import UrlNotFound
12
from gease.contributors import EndPoint
23

34

45
def get_contributors(user, repo, author):
56
repo = EndPoint(user, repo)
6-
user_list = repo.get_all_contributors()
7+
try:
8+
user_list = repo.get_all_contributors()
79

8-
user_list = [detail for detail in user_list if author not in detail["url"]]
9-
return user_list
10+
user_list = [
11+
detail for detail in user_list if author not in detail["url"]
12+
]
13+
return user_list
14+
except UrlNotFound:
15+
return []

tests/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ isort
88
collective.checkdocs
99
pygments
1010
moban
11+
moban_jinja2_github
1112
moban
1213
black;python_version>="3.6"
1314
isort;python_version>="3.6"

tests/test_contributors.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from mock import MagicMock, patch
22
from nose.tools import eq_
3+
from gease.exceptions import UrlNotFound
34

45

56
@patch("moban_jinja2_github.contributors.EndPoint")
@@ -16,3 +17,18 @@ def test_get_contributors(fake_end_point):
1617
expected = [{"url": "contributors"}]
1718

1819
eq_(list(actual), expected)
20+
21+
22+
@patch("moban_jinja2_github.contributors.EndPoint")
23+
def test_get_non_existent_url(fake_end_point):
24+
fake_api = MagicMock(
25+
get_all_contributors=MagicMock(side_effect=UrlNotFound)
26+
)
27+
fake_end_point.return_value = fake_api
28+
29+
from moban_jinja2_github.contributors import get_contributors
30+
31+
actual = get_contributors("user", "repo", "author")
32+
expected = []
33+
34+
eq_(list(actual), expected)

0 commit comments

Comments
 (0)