package com.github.mobile.android.core.repo;

import static org.eclipse.egit.github.core.event.Event.TYPE_FORK;

import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.event.Event;
import org.eclipse.egit.github.core.event.EventPayload;
import org.eclipse.egit.github.core.event.ForkPayload;

/**
 * Helper to find a {@link RepositoryEventMatcher} to open for an event
 */
public class RepositoryEventMatcher {

    /**
     * Get {@link Repository} from event
     *
     * @param event
     * @return gist or null if event doesn't apply
     */
    public Repository getRepository(final Event event) {
        if (event == null)
            return null;
        EventPayload payload = event.getPayload();
        if (payload == null)
            return null;
        String type = event.getType();
        if (TYPE_FORK.equals(type))
            return ((ForkPayload) payload).getForkee();
        else
            return null;
    }
}

@@ -39,16 +39,84 @@
 .repo;%0A%0A
+import static org.eclipse.egit.github.core.event.Event.TYPE_CREATE;%0A
 import s
@@ -173,16 +173,16 @@
 E_FORK;%0A
-
 %0Aimport 
@@ -222,16 +222,58 @@
 sitory;%0A
+import org.eclipse.egit.github.core.User;%0A
 import o
@@ -369,16 +369,75 @@
 ayload;%0A
+import org.eclipse.egit.github.core.event.EventRepository;%0A
 import o
@@ -1095,21 +1095,871 @@
     else
-%0A    
+ if (TYPE_CREATE.equals(type)) %7B%0A            EventRepository repo = event.getRepo();%0A            if (repo != null) %7B%0A                String id = repo.getName();%0A                int slash = id.indexOf('/');%0A                if (slash %3E 0 && slash + 1 %3C id.length()) %7B%0A                    Repository full = new Repository();%0A                    full.setName(id.substring(slash + 1));%0A                    String login = id.substring(0, slash);%0A                    // Use actor if it matches login parsed from repository id%0A                    if (event.getActor() != null && login.equals(event.getActor().getLogin()))%0A                        full.setOwner(event.getActor());%0A                    else%0A                        full.setOwner(new User().setLogin(id.substring(0, slash)));%0A                    return full;%0A                %7D%0A            %7D%0A        %7D%0A
         

Support opening repositories from create events