[SPARK-28053][INFRA] Handle a corner case where there is no Link header - #24874
[SPARK-28053][INFRA] Handle a corner case where there is no Link header#24874dongjoon-hyun wants to merge 1 commit into
Link header#24874Conversation
|
Hi, @HyukjinKwon . |
| # Check if there is another page | ||
| link_header = filter(lambda k: k.startswith("Link"), page.info().headers)[0] | ||
| if "next" not in link_header: | ||
| link_headers = filter(lambda k: k.startswith("Link"), page.info().headers) |
There was a problem hiding this comment.
Just wanted to leave a note that filter returns a generator from Python 3... in fact this whole script should be fixed anyway as of SPARK-27889 separately.
>>> filter(lambda x: x, ['a'])[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'filter' object is not subscriptable
>>> list(filter(lambda x: x, ['a']))[0]
'a'| link_header = filter(lambda k: k.startswith("Link"), page.info().headers)[0] | ||
| if "next" not in link_header: | ||
| link_headers = filter(lambda k: k.startswith("Link"), page.info().headers) | ||
| if not link_headers or "next" not in link_headers[0]: |
There was a problem hiding this comment.
not link_headers is an idiomatic to check if the list is empty. I personally encourage people to use explicit len(...) > 0 comparison (and arguably other projects do too more (?)). But I guess it's my preference just for now. It might be fine.
There was a problem hiding this comment.
I'll use len(...) > 0 for the next time~
|
I don't think this script is tested in our PR builder. linter is enough. I'll merge this one after the linter passes |
|
Merged to master. |
|
Thank you so much for the review and merge, @HyukjinKwon ! |
|
Test build #106508 has finished for PR 24874 at commit
|
## What changes were proposed in this pull request? This PR aims to expose JIRA issue component types at GitHub PRs. ## How was this patch tested? Manual. ``` $ export GITHUB_OAUTH_KEY=... $ export JIRA_PASSWORD=... $ export GITHUB_API_BASE='https://api.github.com/repos/your-id/spark' $ dev/github_jira_sync.py ``` Please note that the existing script will raise the following exceptions if your repo has less than 100 PRs. This will be handled at #24874 . ``` Traceback (most recent call last): File "dev/github_jira_sync.py", line 139, in <module> jira_prs = get_jira_prs() File "dev/github_jira_sync.py", line 83, in get_jira_prs link_header = filter(lambda k: k.startswith("Link"), page.info().headers)[0] IndexError: list index out of range ``` That is beyond the scope of this PR. Closes #24871 from dongjoon-hyun/SPARK-28051. Authored-by: Dongjoon Hyun <dhyun@apple.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
…ader
## What changes were proposed in this pull request?
Currently, `github_jira_sync.py` assumes that there is `Link` always. However, it will fail when the number of the open PR is less than 100 (the default paging number). It will not happen in Apache Spark, but we had better fix that because it happens during review process for `github_jira_sync.py` script.
```
Traceback (most recent call last):
File "dev/github_jira_sync.py", line 139, in <module>
jira_prs = get_jira_prs()
File "dev/github_jira_sync.py", line 83, in get_jira_prs
link_header = filter(lambda k: k.startswith("Link"), page.info().headers)[0]
IndexError: list index out of range
```
## How was this patch tested?
Manually check with another repo which has small number of open PRs (< 100).
```
$ export JIRA_PASSWORD=...
$ export GITHUB_API_BASE='https://api.github.com/repos/your-id/spark'
$ dev/github_jira_sync.py
```
Closes apache#24874 from dongjoon-hyun/SPARK-28053.
Authored-by: Dongjoon Hyun <dhyun@apple.com>
Signed-off-by: HyukjinKwon <gurwls223@apache.org>
## What changes were proposed in this pull request? This PR aims to expose JIRA issue component types at GitHub PRs. ## How was this patch tested? Manual. ``` $ export GITHUB_OAUTH_KEY=... $ export JIRA_PASSWORD=... $ export GITHUB_API_BASE='https://api.github.com/repos/your-id/spark' $ dev/github_jira_sync.py ``` Please note that the existing script will raise the following exceptions if your repo has less than 100 PRs. This will be handled at apache#24874 . ``` Traceback (most recent call last): File "dev/github_jira_sync.py", line 139, in <module> jira_prs = get_jira_prs() File "dev/github_jira_sync.py", line 83, in get_jira_prs link_header = filter(lambda k: k.startswith("Link"), page.info().headers)[0] IndexError: list index out of range ``` That is beyond the scope of this PR. Closes apache#24871 from dongjoon-hyun/SPARK-28051. Authored-by: Dongjoon Hyun <dhyun@apple.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
What changes were proposed in this pull request?
Currently,
github_jira_sync.pyassumes that there isLinkalways. However, it will fail when the number of the open PR is less than 100 (the default paging number). It will not happen in Apache Spark, but we had better fix that because it happens during review process forgithub_jira_sync.pyscript.How was this patch tested?
Manually check with another repo which has small number of open PRs (< 100).