Added support for Gitea and Gogs services.

This commit is contained in:
David Russell 2017-05-15 17:32:26 +07:00
parent 5d354a2cfd
commit 1302e8f369
7 changed files with 488 additions and 1 deletions

View File

@ -58,6 +58,8 @@ public class Module extends AbstractModule {
bind(GitHub.class).asEagerSingleton();
bind(GitLab.class).asEagerSingleton();
bind(BitBucket.class).asEagerSingleton();
bind(Gitea.class).asEagerSingleton();
bind(Gogs.class).asEagerSingleton();
bind(FrontEndThreads.class).asEagerSingleton();
bind(BackEndThreads.class).asEagerSingleton();
bind(Dependencies.class).asEagerSingleton();

View File

@ -48,6 +48,8 @@ public class GRSManager {
private final GitHub gitHubService;
private final GitLab gitLabService;
private final BitBucket bitBucketService;
private final Gitea giteaService;
private final Gogs gogsService;
private final Configuration cfg;
private final Map<String,GRS> grsStore = new HashMap<String,GRS>();
private GRS grsDefault;
@ -57,6 +59,8 @@ public class GRSManager {
GitHub gitHubService,
GitLab gitLabService,
BitBucket bitBucketService,
Gitea giteaService,
Gogs gogsService,
Configuration cfg) {
this.diskService = diskService;
@ -70,6 +74,12 @@ public class GRSManager {
this.bitBucketService = bitBucketService;
this.bitBucketService.init(this, diskService);
this.giteaService = giteaService;
this.giteaService.init(this, diskService);
this.gogsService = gogsService;
this.gogsService.init(this, diskService);
this.cfg = cfg;
List grsCfg = cfg.getList("gitpitch.git.repo.services");
@ -140,6 +150,14 @@ public class GRSManager {
log.debug("getService: matching BitBucket");
service = bitBucketService;
break;
case Gitea.TYPE:
log.debug("getService: matching Gitea");
service = giteaService;
break;
case Gogs.TYPE:
log.debug("getService: matching Gogs");
service = gogsService;
break;
default:
log.debug("getService: defaulting GitHub");
service = gitHubService;

78
app/com/gitpitch/git/vendors/Gitea.java vendored Normal file
View File

@ -0,0 +1,78 @@
/*
* MIT License
*
* Copyright (c) 2016 David Russell
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.gitpitch.git.vendors;
import com.gitpitch.git.*;
import com.gitpitch.models.*;
import com.gitpitch.services.DiskService;
import com.gitpitch.utils.PitchParams;
import com.fasterxml.jackson.databind.JsonNode;
import java.nio.file.Path;
import java.util.*;
import javax.inject.*;
import play.Logger;
import play.Logger.ALogger;
/*
* Gitea API Service.
*/
@Singleton
public class Gitea extends GRSService {
private final Logger.ALogger log = Logger.of(this.getClass());
public GitRepoModel model(PitchParams pp, JsonNode json) {
return GiteaRepoModel.build(pp, json);
}
public String raw(PitchParams pp) {
GRS grs = grsManager.get(pp);
return new StringBuffer(grs.getRawBase())
.append(pp.user)
.append(SLASH)
.append(pp.repo)
.append(GITEA_RAW)
.append(pp.branch)
.append(SLASH)
.toString();
}
public String repo(PitchParams pp) {
GRS grs = grsManager.get(pp);
return new StringBuffer(grs.getApiBase())
.append(GITEA_REPO_API)
.append(pp.user)
.append(SLASH)
.append(pp.repo)
.toString();
}
public static final String TYPE = "gitea";
private static final String GITEA_REPO_API = "repos/";
private static final String GITEA_RAW = "/raw/";
}

78
app/com/gitpitch/git/vendors/Gogs.java vendored Normal file
View File

@ -0,0 +1,78 @@
/*
* MIT License
*
* Copyright (c) 2016 David Russell
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.gitpitch.git.vendors;
import com.gitpitch.git.*;
import com.gitpitch.models.*;
import com.gitpitch.services.DiskService;
import com.gitpitch.utils.PitchParams;
import com.fasterxml.jackson.databind.JsonNode;
import java.nio.file.Path;
import java.util.*;
import javax.inject.*;
import play.Logger;
import play.Logger.ALogger;
/*
* Gogs API Service.
*/
@Singleton
public class Gogs extends GRSService {
private final Logger.ALogger log = Logger.of(this.getClass());
public GitRepoModel model(PitchParams pp, JsonNode json) {
return GogsRepoModel.build(pp, json);
}
public String raw(PitchParams pp) {
GRS grs = grsManager.get(pp);
return new StringBuffer(grs.getRawBase())
.append(pp.user)
.append(SLASH)
.append(pp.repo)
.append(GOGS_RAW)
.append(pp.branch)
.append(SLASH)
.toString();
}
public String repo(PitchParams pp) {
GRS grs = grsManager.get(pp);
return new StringBuffer(grs.getApiBase())
.append(GOGS_REPO_API)
.append(pp.user)
.append(SLASH)
.append(pp.repo)
.toString();
}
public static final String TYPE = "gogs";
private static final String GOGS_REPO_API = "repos/";
private static final String GOGS_RAW = "/raw/";
}

View File

@ -0,0 +1,145 @@
/*
* MIT License
*
* Copyright (c) 2016 David Russell
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.gitpitch.models;
import com.fasterxml.jackson.databind.JsonNode;
import com.gitpitch.utils.PitchParams;
import play.Logger;
import play.Logger.ALogger;
import java.util.*;
/*
* Rendering model for views.Landing.scala.html.
*/
public class GiteaRepoModel extends GitRepoModel {
private final Logger.ALogger log = Logger.of(this.getClass());
/*
* Initialize instance of GiteaRepoModel.
*/
private GiteaRepoModel(PitchParams pp) {
this(pp, null);
}
/*
* Initialize instance of GiteaRepoModel.
*/
private GiteaRepoModel(PitchParams pp, JsonNode json) {
this._pp = pp;
this._pretty = new StringBuffer(SLASH)
.append(this._pp.user)
.append(SLASH)
.append(this._pp.repo)
.toString();
this._cacheKey = genKey(pp);
/*
* Generate derived data on instance only if the GitHub
* API JSON is available for processing.
*/
if (json != null) {
JsonNode ownerNode = json.findPath("owner");
this._type = null;
this._desc = json.findPath("description").textValue();
this._created = json.findPath("created_at").textValue();
this._updated = json.findPath("updated_at").textValue();
this._lang = null;
this._stars = json.findPath("stars_count").asInt();
this._forks = json.findPath("forks_count").asInt();
this._issues = json.findPath("open_issues.count").asInt();
this._hasWiki = false;
this._hasPages = false;
} else {
this._type = null;
this._desc = null;
this._created = null;
this._updated = null;
this._lang = null;
this._stars = 0;
this._forks = 0;
this._issues = 0;
this._hasWiki = false;
this._hasPages = false;
}
}
public static GitRepoModel build(PitchParams pp) {
return build(pp, null);
}
public static GitRepoModel build(PitchParams pp, JsonNode json) {
return new GiteaRepoModel(pp, json);
}
public String owner() {
return _pp.user;
}
public String name() {
return _pp.repo;
}
public String description() {
return _desc;
}
public String lang() {
return _lang;
}
public boolean byOrg() {
return false;
}
public int stargazers() {
return _stars;
}
public int forks() {
return _forks;
}
public String toString() {
return _pretty;
}
public String key() {
return _cacheKey;
}
}

View File

@ -0,0 +1,145 @@
/*
* MIT License
*
* Copyright (c) 2016 David Russell
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.gitpitch.models;
import com.fasterxml.jackson.databind.JsonNode;
import com.gitpitch.utils.PitchParams;
import play.Logger;
import play.Logger.ALogger;
import java.util.*;
/*
* Rendering model for views.Landing.scala.html.
*/
public class GogsRepoModel extends GitRepoModel {
private final Logger.ALogger log = Logger.of(this.getClass());
/*
* Initialize instance of GogsRepoModel.
*/
private GogsRepoModel(PitchParams pp) {
this(pp, null);
}
/*
* Initialize instance of GogsRepoModel.
*/
private GogsRepoModel(PitchParams pp, JsonNode json) {
this._pp = pp;
this._pretty = new StringBuffer(SLASH)
.append(this._pp.user)
.append(SLASH)
.append(this._pp.repo)
.toString();
this._cacheKey = genKey(pp);
/*
* Generate derived data on instance only if the GitHub
* API JSON is available for processing.
*/
if (json != null) {
JsonNode ownerNode = json.findPath("owner");
this._type = null;
this._desc = json.findPath("description").textValue();
this._created = json.findPath("created_at").textValue();
this._updated = json.findPath("updated_at").textValue();
this._lang = null;
this._stars = json.findPath("stars_count").asInt();
this._forks = json.findPath("forks_count").asInt();
this._issues = json.findPath("open_issues.count").asInt();
this._hasWiki = false;
this._hasPages = false;
} else {
this._type = null;
this._desc = null;
this._created = null;
this._updated = null;
this._lang = null;
this._stars = 0;
this._forks = 0;
this._issues = 0;
this._hasWiki = false;
this._hasPages = false;
}
}
public static GitRepoModel build(PitchParams pp) {
return build(pp, null);
}
public static GitRepoModel build(PitchParams pp, JsonNode json) {
return new GogsRepoModel(pp, json);
}
public String owner() {
return _pp.user;
}
public String name() {
return _pp.repo;
}
public String description() {
return _desc;
}
public String lang() {
return _lang;
}
public boolean byOrg() {
return false;
}
public int stargazers() {
return _stars;
}
public int forks() {
return _forks;
}
public String toString() {
return _pretty;
}
public String key() {
return _cacheKey;
}
}

View File

@ -451,7 +451,28 @@ gitpitch {
rawbase = "https://bitbucket.org/"
default = "false"
}
{
name = "Gitea"
type = "gitea"
site = "https://gitea.io"
apibase = "http://localhost:3000/api/v1/"
apibase = "https://try.gitea.io/api/v1/"
// apitoken = "token your-gitea-app-token-here"
apitokenheader = "Authorization"
rawbase = "http://localhost:3000/"
default = "false"
}
{
name = "Gogs"
type = "gogs"
site = "https://gogs.io"
apibase = "http://localhost:3000/api/v1/"
apitoken = "token your-gitea-app-token-here"
apitokenheader = "Authorization"
rawbase = "http://localhost:3000/"
rawbase = "https://try.gogs.io/"
default = "false"
}
]
}
}