Skip to content
Snippets Groups Projects
Commit 1941b76a authored by John Carlson's avatar John Carlson
Browse files

Extensions for build utils

parent 879066b5
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -93,7 +93,7 @@ open class App : Application() {
fun setAccount(account: Account) {
currentAccount = account
//This is kinda weird, but basically, I don't want to see all the annoying logs from bitmap
//decoding since the Okhttpclient is going to log everything, but it does not matter in release
//decoding since the OkHttpClient is going to log everything, but it does not matter in release
//builds, and will actually speed up the init time to share the same client between all these
val clientBuilder = OkHttpClientFactory.create(account)
if (BuildConfig.DEBUG) {
Loading
Loading
Loading
Loading
@@ -24,13 +24,13 @@ import com.commit451.gitlab.model.Account
import com.commit451.gitlab.model.api.Build
import com.commit451.gitlab.model.api.Project
import com.commit451.gitlab.rx.CustomSingleObserver
import com.commit451.gitlab.util.BuildUtil
import com.commit451.gitlab.util.DownloadUtil
 
import org.parceler.Parcels
 
import butterknife.BindView
import butterknife.ButterKnife
import com.commit451.gitlab.extension.getDownloadBuildUrl
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import timber.log.Timber
Loading
Loading
@@ -207,7 +207,7 @@ class BuildActivity : BaseActivity() {
 
private fun downloadBuild() {
val account = App.get().getAccount()
val downloadUrl = BuildUtil.getDownloadBuildUrl(App.get().getAccount().serverUrl, project, build)
val downloadUrl = build.getDownloadBuildUrl(App.get().getAccount().serverUrl, project)
Timber.d("Downloading build: " + downloadUrl)
DownloadUtil.download(this@BuildActivity, account, downloadUrl, build.artifactsFile.fileName)
}
Loading
Loading
package com.commit451.gitlab.extension
import android.net.Uri
import com.commit451.gitlab.api.GitLab
import com.commit451.gitlab.model.api.Build
import com.commit451.gitlab.model.api.Project
fun Build.getRawBuildUrl(baseUrl: Uri, project: Project): String {
return baseUrl.toString() + project.pathWithNamespace + "/builds/" + id + "/raw"
}
fun Build.getDownloadBuildUrl(baseUrl: Uri, project: Project): String {
return baseUrl.toString() + GitLab.API_VERSION + "/projects/" + project.id + "/builds/" + id + "/artifacts"
}
Loading
Loading
@@ -11,10 +11,10 @@ import butterknife.BindView
import com.commit451.gitlab.App
import com.commit451.gitlab.R
import com.commit451.gitlab.event.BuildChangedEvent
import com.commit451.gitlab.extension.getRawBuildUrl
import com.commit451.gitlab.model.api.Build
import com.commit451.gitlab.model.api.Project
import com.commit451.gitlab.rx.CustomSingleObserver
import com.commit451.gitlab.util.BuildUtil
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import org.greenrobot.eventbus.Subscribe
Loading
Loading
@@ -81,7 +81,7 @@ class BuildLogFragment : ButterKnifeFragment() {
 
swipeRefreshLayout.isRefreshing = true
 
val url = BuildUtil.getRawBuildUrl(App.get().getAccount().serverUrl, project, build)
val url = build.getRawBuildUrl(App.get().getAccount().serverUrl, project)
 
App.get().gitLab.getRaw(url)
.compose(this.bindToLifecycle<String>())
Loading
Loading
Loading
Loading
@@ -9,6 +9,8 @@ import io.reactivex.Single
object DecodeObservableFactory {
 
fun newDecode(string: String): Single<ByteArray> {
return Single.defer { Single.just(Base64.decode(string, Base64.DEFAULT)) }
return Single.defer {
Single.just(Base64.decode(string, Base64.DEFAULT))
}
}
}
Loading
Loading
@@ -11,6 +11,8 @@ import java.io.File
object FileObservableFactory {
 
fun toPart(file: File): Single<MultipartBody.Part> {
return Single.defer { Single.just(FileUtil.toPart(file)) }
return Single.defer {
Single.just(FileUtil.toPart(file))
}
}
}
package com.commit451.gitlab.util
import android.net.Uri
import com.commit451.gitlab.api.GitLab
import com.commit451.gitlab.model.api.Build
import com.commit451.gitlab.model.api.Project
/**
* Util related to [com.commit451.gitlab.model.api.Build] things
*/
object BuildUtil {
fun getRawBuildUrl(baseUrl: Uri, project: Project, build: Build): String {
return baseUrl.toString() + project.pathWithNamespace + "/builds/" + build.id + "/raw"
}
fun getDownloadBuildUrl(baseUrl: Uri, project: Project, build: Build): String {
return baseUrl.toString() + GitLab.API_VERSION + "/projects/" + project.id + "/builds/" + build.id + "/artifacts"
}
}
Loading
Loading
@@ -41,7 +41,7 @@ public class ApiTests {
 
private static final long FAKE_GROUP_PROJECT_ID = 376651;
 
private static Project sFakeProject;
private static Project fakeProject;
private static GitLab gitLab;
 
@BeforeClass
Loading
Loading
@@ -58,7 +58,7 @@ public class ApiTests {
.blockingGet();
assertNotNull(projectResponse);
 
sFakeProject = projectResponse;
fakeProject = projectResponse;
}
 
@Test
Loading
Loading
@@ -94,7 +94,7 @@ public class ApiTests {
public void getIssues() throws Exception {
String defaultState = RuntimeEnvironment.application.getResources().getString(R.string.issue_state_value_default);
Response<List<Issue>> issuesResponse = gitLab
.getIssues(sFakeProject.getId(), defaultState)
.getIssues(fakeProject.getId(), defaultState)
.blockingGet();
TestUtil.assertRetrofitResponseSuccess(issuesResponse);
assertNotNull(issuesResponse.body());
Loading
Loading
@@ -105,7 +105,7 @@ public class ApiTests {
String defaultBranch = "master";
String currentPath = "";
List<RepositoryTreeObject> treeResponse = gitLab
.getTree(sFakeProject.getId(), defaultBranch, currentPath)
.getTree(fakeProject.getId(), defaultBranch, currentPath)
.blockingGet();
assertNotNull(treeResponse);
}
Loading
Loading
@@ -114,7 +114,7 @@ public class ApiTests {
public void getCommits() throws Exception {
String defaultBranch = "master";
List<RepositoryCommit> commitsResponse = gitLab
.getCommits(sFakeProject.getId(), defaultBranch, 0)
.getCommits(fakeProject.getId(), defaultBranch, 0)
.blockingGet();
assertNotNull(commitsResponse);
}
Loading
Loading
@@ -123,7 +123,7 @@ public class ApiTests {
public void getMergeRequests() throws Exception {
String defaultState = RuntimeEnvironment.application.getResources().getString(R.string.merge_request_state_value_default);
Response<List<MergeRequest>> mergeRequestResponse = gitLab
.getMergeRequests(sFakeProject.getId(), defaultState)
.getMergeRequests(fakeProject.getId(), defaultState)
.blockingGet();
TestUtil.assertRetrofitResponseSuccess(mergeRequestResponse);
assertNotNull(mergeRequestResponse.body());
Loading
Loading
@@ -144,7 +144,7 @@ public class ApiTests {
MultipartBody.Part part = FileUtil.INSTANCE.toPart(bitmap, "fork.png");
 
FileUploadResponse uploadResponseResponse =
gitLab.uploadFile(sFakeProject.getId(), part)
gitLab.uploadFile(fakeProject.getId(), part)
.blockingGet();
assertNotNull(uploadResponseResponse);
}
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment