Skip to content

[SPARK-28053][INFRA] Handle a corner case where there is no Link header - #24874

Closed
dongjoon-hyun wants to merge 1 commit into
apache:masterfrom
dongjoon-hyun:SPARK-28053
Closed

[SPARK-28053][INFRA] Handle a corner case where there is no Link header#24874
dongjoon-hyun wants to merge 1 commit into
apache:masterfrom
dongjoon-hyun:SPARK-28053

Conversation

@dongjoon-hyun

Copy link
Copy Markdown
Member

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

@dongjoon-hyun

dongjoon-hyun commented Jun 14, 2019

Copy link
Copy Markdown
Member Author

Hi, @HyukjinKwon .
Could you review this PR? This will be needed for the review process of #24871 .

Comment thread dev/github_jira_sync.py
# 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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'

Comment thread dev/github_jira_sync.py
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]:

@HyukjinKwon HyukjinKwon Jun 14, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll use len(...) > 0 for the next time~

@HyukjinKwon

Copy link
Copy Markdown
Member

I don't think this script is tested in our PR builder. linter is enough. I'll merge this one after the linter passes

@HyukjinKwon

Copy link
Copy Markdown
Member

Merged to master.

@dongjoon-hyun

Copy link
Copy Markdown
Member Author

Thank you so much for the review and merge, @HyukjinKwon !

@dongjoon-hyun
dongjoon-hyun deleted the SPARK-28053 branch June 14, 2019 08:03
@SparkQA

SparkQA commented Jun 14, 2019

Copy link
Copy Markdown

Test build #106508 has finished for PR 24874 at commit bcecc49.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

dongjoon-hyun added a commit that referenced this pull request Jun 15, 2019
## 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>
emanuelebardelli pushed a commit to emanuelebardelli/spark that referenced this pull request Jun 15, 2019
…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>
emanuelebardelli pushed a commit to emanuelebardelli/spark that referenced this pull request Jun 15, 2019
## 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants