Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #102 from vase4kin/dev
Browse files Browse the repository at this point in the history
Release 1.2.5
  • Loading branch information
vase4kin authored Oct 14, 2017
2 parents 98e5ae0 + c1d9a76 commit edca4ca
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 29 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[![License](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)
[![Circle CI](https://circleci.com/gh/vase4kin/TeamCityApp/tree/master.svg?style=shield)](https://circleci.com/gh/vase4kin/TeamCityApp/tree/master)
[![codecov](https://codecov.io/gh/vase4kin/TeamCityApp/branch/master/graph/badge.svg)](https://codecov.io/gh/vase4kin/TeamCityApp)
[![Release](https://img.shields.io/badge/release-1.2.4-blue.svg)](https://github.com/vase4kin/TeamCityApp/releases/latest)
[![Release](https://img.shields.io/badge/release-1.2.5-blue.svg)](https://github.com/vase4kin/TeamCityApp/releases/latest)

```
* ) ( ) (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,23 @@ public void setUp() throws Exception {
}

@Test
public void formatUrl() throws Exception {
assertThat(mUrlFormatter.formatUrl("https://teamcity.com"), is(equalTo("https://teamcity.com")));
assertThat(mUrlFormatter.formatUrl("https://teamcity.com/"), is(equalTo("https://teamcity.com/")));
public void testFormatServerUrl() throws Exception {
assertThat(mUrlFormatter.formatServerUrl("https://teamcity.com"), is(equalTo("https://teamcity.com")));
assertThat(mUrlFormatter.formatServerUrl("https://teamcity.com/"), is(equalTo("https://teamcity.com/")));
}

@Test
public void formatUrlWithPath() throws Exception {
assertThat(mUrlFormatter.formatUrl("https://teamcity.com/server"), is(equalTo("https://teamcity.com/server/")));
assertThat(mUrlFormatter.formatUrl("https://teamcity.com/server/"), is(equalTo("https://teamcity.com/server/")));
assertThat(mUrlFormatter.formatUrl("https://teamcity.com/server/v2"), is(equalTo("https://teamcity.com/server/v2/")));
assertThat(mUrlFormatter.formatUrl("https://teamcity.com/server/v2/"), is(equalTo("https://teamcity.com/server/v2/")));
public void testFormatServerUrlWithPath() throws Exception {
assertThat(mUrlFormatter.formatServerUrl("https://teamcity.com/server"), is(equalTo("https://teamcity.com/server/")));
assertThat(mUrlFormatter.formatServerUrl("https://teamcity.com/server/"), is(equalTo("https://teamcity.com/server/")));
assertThat(mUrlFormatter.formatServerUrl("https://teamcity.com/server/v2"), is(equalTo("https://teamcity.com/server/v2/")));
assertThat(mUrlFormatter.formatServerUrl("https://teamcity.com/server/v2/"), is(equalTo("https://teamcity.com/server/v2/")));
}

@Test
public void testFormatUrl() throws Exception {
assertThat(mUrlFormatter.formatBasicUrl("/app/rest/buildTypes/id:buildType/builds?locator=locator:any"), is(equalTo("app/rest/buildTypes/id:buildType/builds?locator=locator:any")));
assertThat(mUrlFormatter.formatBasicUrl("app/rest/buildTypes/id:buildType/builds?locator=locator:any"), is(equalTo("app/rest/buildTypes/id:buildType/builds?locator=locator:any")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void onResponse(Call call, final Response response) throws IOException {
@Override
public void run() {
if (response.isSuccessful()) {
String formattedServerUrl = mUrlFormatter.formatUrl(serverUrl);
String formattedServerUrl = mUrlFormatter.formatServerUrl(serverUrl);
listener.onSuccess(formattedServerUrl);
} else {
listener.onFail(response.code(), response.message());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.github.vase4kin.teamcityapp.account.create.helper;

import android.support.annotation.NonNull;

/**
* Url formatter
*/
Expand All @@ -27,5 +29,17 @@ public interface UrlFormatter {
* @param serverUrl - Server url to format
* @return formatted server url
*/
String formatUrl(String serverUrl);
String formatServerUrl(String serverUrl);

/**
* Remove leading slash from url to able load data if server url contains trailing path, teamcity.com/server
* <p>
* https://github.com/square/retrofit/issues/907
* <p>
* ¯\_(ツ)_/¯
* <p>
* /app/rest/buildTypes/id:buildType/builds?locator=locator:any - > app/rest/buildTypes/id:buildType/builds?locator=locator:any
*/
String formatBasicUrl(@NonNull String url);
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.github.vase4kin.teamcityapp.account.create.helper;

import android.net.Uri;
import android.support.annotation.NonNull;
import android.text.TextUtils;

/**
Expand All @@ -27,7 +28,7 @@ public class UrlFormatterImpl implements UrlFormatter {
/**
* {@inheritDoc}
*/
public String formatUrl(String serverUrl) {
public String formatServerUrl(String serverUrl) {
Uri serverUri = Uri.parse(serverUrl);
boolean hasNoPathSegment = TextUtils.isEmpty(serverUri.getLastPathSegment());
if (hasNoPathSegment) {
Expand All @@ -39,4 +40,17 @@ public String formatUrl(String serverUrl) {
return serverUri.buildUpon().appendPath("").toString();
}
}

/**
* {@inheritDoc}
*/
@Override
public String formatBasicUrl(@NonNull String url) {
// Check that url has leading slash
if (url.startsWith("/")) {
return url.replaceFirst("/", "");
} else {
return url;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.support.annotation.Nullable;

import com.github.vase4kin.teamcityapp.account.create.helper.UrlFormatter;
import com.github.vase4kin.teamcityapp.agents.api.Agents;
import com.github.vase4kin.teamcityapp.api.cache.CacheProviders;
import com.github.vase4kin.teamcityapp.artifact.api.Files;
Expand All @@ -44,10 +45,14 @@ public class RepositoryImpl implements Repository {

private final TeamCityService mTeamCityService;
private final CacheProviders mCacheCacheProviders;
private final UrlFormatter urlFormatter;

public RepositoryImpl(TeamCityService teamCityService, CacheProviders cacheProviders) {
public RepositoryImpl(TeamCityService teamCityService,
CacheProviders cacheProviders,
UrlFormatter urlFormatter) {
this.mTeamCityService = teamCityService;
this.mCacheCacheProviders = cacheProviders;
this.urlFormatter = urlFormatter;
}

/**
Expand All @@ -73,7 +78,10 @@ public Observable<Agents> listAgents(@Nullable Boolean includeDisconnected,
*/
@Override
public Observable<NavigationNode> listBuildTypes(String url, boolean update) {
return mCacheCacheProviders.listBuildTypes(mTeamCityService.listBuildTypes(url), new DynamicKey(url), new EvictDynamicKey(update));
return mCacheCacheProviders.listBuildTypes(
mTeamCityService.listBuildTypes(urlFormatter.formatBasicUrl(url)),
new DynamicKey(url),
new EvictDynamicKey(update));
}

/**
Expand All @@ -93,7 +101,7 @@ public Observable<BuildType> buildType(String id, boolean update) {
@Override
public Observable<Build> build(String url, boolean update) {
return mCacheCacheProviders.build(
mTeamCityService.build(url),
mTeamCityService.build(urlFormatter.formatBasicUrl(url)),
new DynamicKey(url),
new EvictDynamicKey(update));
}
Expand Down Expand Up @@ -136,7 +144,7 @@ public Observable<Builds> listQueueBuilds(String fields, boolean update) {
*/
@Override
public Observable<Builds> listMoreBuilds(String url) {
return mTeamCityService.listMoreBuilds(url);
return mTeamCityService.listMoreBuilds(urlFormatter.formatBasicUrl(url));
}

/**
Expand All @@ -145,7 +153,7 @@ public Observable<Builds> listMoreBuilds(String url) {
@Override
public Observable<Files> listArtifacts(String url, String locator, boolean update) {
return mCacheCacheProviders.listArtifacts(
mTeamCityService.listArtifacts(url, locator),
mTeamCityService.listArtifacts(urlFormatter.formatBasicUrl(url), locator),
new DynamicKey(url),
new EvictDynamicKey(update));
}
Expand All @@ -155,39 +163,47 @@ public Observable<Files> listArtifacts(String url, String locator, boolean updat
*/
@Override
public Observable<ResponseBody> downloadFile(String url) {
return mTeamCityService.downloadFile(url);
return mTeamCityService.downloadFile(urlFormatter.formatBasicUrl(url));
}

/**
* {@inheritDoc}
*/
@Override
public Observable<TestOccurrences> listTestOccurrences(String url, boolean update) {
return mCacheCacheProviders.listTestOccurrences(mTeamCityService.listTestOccurrences(url), new DynamicKey(url), new EvictDynamicKey(update));
return mCacheCacheProviders.listTestOccurrences(
mTeamCityService.listTestOccurrences(urlFormatter.formatBasicUrl(url)),
new DynamicKey(url),
new EvictDynamicKey(update));
}

/**
* {@inheritDoc}
*/
@Override
public Observable<TestOccurrences.TestOccurrence> testOccurrence(String url) {
return mCacheCacheProviders.testOccurrence(mTeamCityService.testOccurrence(url), new DynamicKey(url));
return mCacheCacheProviders.testOccurrence(
mTeamCityService.testOccurrence(urlFormatter.formatBasicUrl(url)),
new DynamicKey(url));
}

/**
* {@inheritDoc}
*/
@Override
public Observable<Changes> listChanges(String url, boolean update) {
return mCacheCacheProviders.listChanges(mTeamCityService.listChanges(url), new DynamicKey(url), new EvictDynamicKey(update));
return mCacheCacheProviders.listChanges(
mTeamCityService.listChanges(urlFormatter.formatBasicUrl(url)),
new DynamicKey(url),
new EvictDynamicKey(update));
}

/**
* {@inheritDoc}
*/
@Override
public Observable<Changes.Change> change(String url) {
return mCacheCacheProviders.change(mTeamCityService.change(url), new DynamicKey(url));
return mCacheCacheProviders.change(mTeamCityService.change(urlFormatter.formatBasicUrl(url)), new DynamicKey(url));
}

/**
Expand All @@ -211,6 +227,6 @@ public Observable<Build> queueBuild(Build build) {
*/
@Override
public Observable<Build> cancelBuild(String url, BuildCancelRequest buildCancelRequest) {
return mTeamCityService.cancelBuild(url, buildCancelRequest);
return mTeamCityService.cancelBuild(urlFormatter.formatBasicUrl(url), buildCancelRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ Observable<Files> listArtifacts(@Url String url,
* @return {@link Observable} with {@link com.github.vase4kin.teamcityapp.changes.api.Changes.Change}
*/
@Headers(APPLICATION_JSON)
@GET("/app/rest/buildTypes/id:{id}/branches?locator=policy:ALL_BRANCHES")
@GET("app/rest/buildTypes/id:{id}/branches?locator=policy:ALL_BRANCHES")
Observable<Branches> listBranches(@Path("id") String id);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.content.Context;

import com.github.vase4kin.teamcityapp.account.create.dagger.UrlFormatterModule;
import com.github.vase4kin.teamcityapp.api.Repository;
import com.github.vase4kin.teamcityapp.api.TeamCityService;
import com.github.vase4kin.teamcityapp.dagger.modules.RestApiModule;
Expand All @@ -32,7 +33,7 @@
import io.rx_cache.internal.RxCache;

@UserScope
@Component(dependencies = AppComponent.class, modules = RestApiModule.class)
@Component(dependencies = AppComponent.class, modules = {RestApiModule.class, UrlFormatterModule.class})
public interface RestApiComponent {

TeamCityService teamCityService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.github.vase4kin.teamcityapp.dagger.modules;

import com.github.vase4kin.teamcityapp.account.create.helper.UrlFormatter;
import com.github.vase4kin.teamcityapp.api.Repository;
import com.github.vase4kin.teamcityapp.api.RepositoryImpl;
import com.github.vase4kin.teamcityapp.api.TeamCityService;
Expand Down Expand Up @@ -56,7 +57,7 @@ TeamCityService provideTeamCityService(@Named(CLIENT_AUTH) OkHttpClient okHttpCl

@Provides
@UserScope
Repository provideRepository(TeamCityService teamCityService, CacheProviders cacheProviders) {
return new RepositoryImpl(teamCityService, cacheProviders);
Repository provideRepository(TeamCityService teamCityService, CacheProviders cacheProviders, UrlFormatter urlFormatter) {
return new RepositoryImpl(teamCityService, cacheProviders, urlFormatter);
}
}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ allprojects {

ext {
// versions
versionCode = 34
versionName = "1.2.4"
versionCode = 35
versionName = "1.2.5"

// sdk and tools
minSdkVersion = 15
Expand Down
1 change: 1 addition & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ jobs:
command: |
sudo apt-get install gcc python-dev python-setuptools
sudo easy_install -U pip
echo y | sudo pip uninstall crcmod
sudo pip install -U crcmod
- run:
name: Install Gcloud
Expand Down

0 comments on commit edca4ca

Please sign in to comment.