GitNex/app/src/main/java/org/mian/gitnex/actions/PullRequestActions.java
qwerty287 fbe55035f2 Move to tea4j-autodeploy (#1088)
Move to https://codeberg.org/GitNex/tea4j-autodeploy as Retrofit interfaces. Closes #907 closes #1084

Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1088
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-04-18 09:10:54 +02:00

114 lines
3 KiB
Java

package org.mian.gitnex.actions;
import android.content.Context;
import androidx.annotation.NonNull;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.Toasty;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* @author qwerty287
*/
public class PullRequestActions {
public static void deleteHeadBranch(Context context, String repoOwner, String repoName, String headBranch, boolean showToasts) {
Call<Void> call = RetrofitClient
.getApiInterface(context)
.repoDeleteBranch(repoOwner, repoName, headBranch);
call.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<Void> call, @NonNull retrofit2.Response<Void> response) {
if(response.code() == 204) {
if(showToasts) {
Toasty.success(context, context.getString(R.string.deleteBranchSuccess));
}
}
else if(response.code() == 401) {
AlertDialogs.authorizationTokenRevokedDialog(context, context.getResources().getString(R.string.alertDialogTokenRevokedTitle),
context.getResources().getString(R.string.alertDialogTokenRevokedMessage),
context.getResources().getString(R.string.cancelButton), context.getResources().getString(R.string.navLogout));
}
else if(response.code() == 403) {
if(showToasts) {
Toasty.error(context, context.getString(R.string.authorizeError));
}
}
else if(response.code() == 404) {
if(showToasts) {
Toasty.warning(context, context.getString(R.string.deleteBranchErrorNotFound));
}
}
else {
if(showToasts) {
Toasty.error(context, context.getString(R.string.genericError));
}
}
}
@Override
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
if(showToasts) {
Toasty.error(context, context.getString(R.string.deleteBranchError));
}
}
});
}
public static void updatePr(Context context, String repoOwner, String repoName, String index, Boolean rebase) {
String strategy;
if(rebase == null) {
strategy = null;
}
else if(!rebase) {
strategy = "merge";
}
else {
strategy = "rebase";
}
RetrofitClient.getApiInterface(context).repoUpdatePullRequest(repoOwner, repoName, Long.valueOf(index), strategy)
.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call call, @NonNull Response response) {
if(response.isSuccessful()) {
Toasty.success(context, context.getString(R.string.updatePrSuccess));
}
else {
if(response.code() == 403) {
Toasty.error(context, context.getString(R.string.authorizeError));
}
else if(response.code() == 409) {
Toasty.error(context, context.getString(R.string.updatePrConflict));
}
else {
Toasty.error(context, context.getString(R.string.genericError));
}
}
}
@Override
public void onFailure(@NonNull Call call, @NonNull Throwable t) {
Toasty.error(context, context.getString(R.string.genericError));
}
});
}
}