package org.bndtools.templating.jgit;

import java.net.URI;
import java.util.concurrent.ExecutorService;

import org.osgi.util.promise.Deferred;
import org.osgi.util.promise.Promise;

import aQute.lib.json.JSONCodec;

public class GitHub {

    private static final String URL_PREFIX = "https://api.github.com/repos/";

    private final Cache cache;
    private final ExecutorService executor;

    public GitHub(Cache cache, ExecutorService executor) {
        this.cache = cache;
        this.executor = executor;
    }

    // TODO: use the async download service when available.
    public Promise<GithubRepoDetailsDTO> loadRepoDetails(final String repository) throws Exception {
        final Deferred<GithubRepoDetailsDTO> deferred = new Deferred<>();
        executor.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    byte[] detailsDtoData = cache.download(URI.create(URL_PREFIX + repository));
                    GithubRepoDetailsDTO detailsDTO = new JSONCodec().dec().from(detailsDtoData).get(GithubRepoDetailsDTO.class);
                    deferred.resolve(detailsDTO);
                } catch (Exception e) {
                    deferred.fail(e);
                }
            }
        });
        return deferred.getPromise();
    }

}

@@ -85,64 +85,63 @@
 ent.
-ExecutorServic
+Callabl
 e;%0A
-%0A
 import 
-org.osgi.util.promise.Deferred;
+java.util.concurrent.ExecutorService;%0A
 %0Aimp
@@ -208,16 +208,58 @@
 ONCodec;
+%0Aimport aQute.lib.promise.PromiseExecutor;
 %0A%0Apublic
@@ -403,24 +403,31 @@
 e final 
+Promise
 Executor
 Service 
@@ -410,39 +410,32 @@
  PromiseExecutor
-Service
  executor;%0A%0A    
@@ -541,24 +541,44 @@
 cutor = 
+new PromiseExecutor(
 executor
 ;%0A    %7D%0A
@@ -569,16 +569,17 @@
 executor
+)
 ;%0A    %7D%0A
@@ -752,195 +752,158 @@
     
-final Deferred%3CGithubRepoDetailsDTO%3E deferred = new Deferred%3C%3E();%0A        executor.submit(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                try %7B%0A    
+return executor.submit(new Callable%3CGithubRepoDetailsDTO%3E() %7B%0A            @Override%0A            public GithubRepoDetailsDTO call() throws Exception %7B%0A
     
@@ -1011,45 +1011,14 @@
     
-    GithubRepoDetailsDTO detailsDTO =
+return
  new
@@ -1106,203 +1106,19 @@
     
-        deferred.resolve(detailsDTO);%0A                %7D catch (Exception e) %7B%0A                    deferred.fail(e);%0A                %7D%0A            %7D%0A        %7D);%0A        return deferred.getPromise(
+%7D%0A        %7D
 );%0A 

Use PromiseExecutor to read github repo details