Skip to content

Commit cb946df

Browse files
committed
Guard against fork event with missing user
This appears to happen if a news feed item is selected for a fork that has been deleted.
1 parent 67b8035 commit cb946df

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

app/src/main/java/com/github/mobile/core/repo/RepositoryEventMatcher.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static org.eclipse.egit.github.core.event.Event.TYPE_CREATE;
1919
import static org.eclipse.egit.github.core.event.Event.TYPE_FORK;
2020
import static org.eclipse.egit.github.core.event.Event.TYPE_WATCH;
21+
import android.text.TextUtils;
2122

2223
import org.eclipse.egit.github.core.Repository;
2324
import org.eclipse.egit.github.core.User;
@@ -46,8 +47,15 @@ public Repository getRepository(final Event event) {
4647
return null;
4748

4849
String type = event.getType();
49-
if (TYPE_FORK.equals(type))
50-
return ((ForkPayload) payload).getForkee();
50+
if (TYPE_FORK.equals(type)) {
51+
Repository repository = ((ForkPayload) payload).getForkee();
52+
// Verify repository has valid name and owner
53+
if (repository != null && !TextUtils.isEmpty(repository.getName())
54+
&& repository.getOwner() != null
55+
&& !TextUtils.isEmpty(repository.getOwner().getLogin()))
56+
return repository;
57+
}
58+
5159
if (TYPE_CREATE.equals(type) || TYPE_WATCH.equals(type))
5260
return getRepository(event.getRepo(), event.getActor());
5361

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2012 GitHub Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.github.mobile.tests.tests.repo;
17+
18+
import android.test.AndroidTestCase;
19+
20+
import com.github.mobile.core.repo.RepositoryEventMatcher;
21+
22+
import org.eclipse.egit.github.core.Repository;
23+
import org.eclipse.egit.github.core.User;
24+
import org.eclipse.egit.github.core.event.Event;
25+
import org.eclipse.egit.github.core.event.ForkPayload;
26+
27+
/**
28+
* Unit tests of {@link RepositoryEventMatcher}
29+
*/
30+
public class RepositoryEventMatcherTest extends AndroidTestCase {
31+
32+
/**
33+
* Test fork event that has an incomplete forkee in the payload
34+
*/
35+
public void testIncompleteRepositoryFork() {
36+
RepositoryEventMatcher matcher = new RepositoryEventMatcher();
37+
Event event = new Event();
38+
event.setType(Event.TYPE_FORK);
39+
ForkPayload payload = new ForkPayload();
40+
event.setPayload(payload);
41+
assertNull(matcher.getRepository(event));
42+
Repository repository = new Repository();
43+
payload.setForkee(repository);
44+
assertNull(matcher.getRepository(event));
45+
repository.setName("repo");
46+
assertNull(matcher.getRepository(event));
47+
repository.setOwner(new User());
48+
assertNull(matcher.getRepository(event));
49+
repository.getOwner().setLogin("owner");
50+
assertEquals(repository, matcher.getRepository(event));
51+
}
52+
53+
}

0 commit comments

Comments
 (0)