mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2024-12-16 15:48:13 +08:00
Add option to delete branch after pr got merged (#929)
### Describe what your pull request does and which issue you’re targeting <!-- Create a new issue, if it doesn't exist yet --> Closes #860 <br><br> <!-- Make sure you are targeting the "main" branch, pull requests on release branches are only allowed for bug fixes. --> - [X] I carefully read the [contribution guidelines](https://codeberg.org/GitNex/GitNex/src/branch/main/CONTRIBUTING.md). - [X] I'm following the code standards as defined [here](https://codeberg.org/gitnex/GitNex/wiki/Code-Standards). - [X] By submitting this pull request, I permit GitNex to license my work under the [GNU General Public License v3](https://codeberg.org/GitNex/GitNex/src/branch/main/LICENSE). Co-authored-by: qwerty287 <ndev@web.de> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/929 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>
This commit is contained in:
parent
0fc845e058
commit
d567a012d8
@ -0,0 +1,62 @@
|
||||
package org.mian.gitnex.actions;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.google.gson.JsonElement;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.helpers.AlertDialogs;
|
||||
import org.mian.gitnex.helpers.Authorization;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
|
||||
/**
|
||||
* Author qwerty287
|
||||
*/
|
||||
|
||||
public class PullRequestActions {
|
||||
|
||||
public static void deleteHeadBranch(Context context, String repoOwner, String repoName, String headBranch, boolean showToasts) {
|
||||
Call<JsonElement> call = RetrofitClient
|
||||
.getApiInterface(context)
|
||||
.deleteBranch(Authorization.get(context), repoOwner, repoName, headBranch);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> 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.alertDialogTokenRevokedCopyNegativeButton), context.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
}
|
||||
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<JsonElement> call, @NonNull Throwable t) {
|
||||
|
||||
if(showToasts) Toasty.error(context, context.getString(R.string.deleteBranchError));
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -12,6 +12,7 @@ import com.google.gson.JsonElement;
|
||||
import org.gitnex.tea4j.models.MergePullRequest;
|
||||
import org.gitnex.tea4j.models.MergePullRequestSpinner;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.actions.PullRequestActions;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.databinding.ActivityMergePullRequestBinding;
|
||||
import org.mian.gitnex.helpers.AlertDialogs;
|
||||
@ -187,7 +188,7 @@ public class MergePullRequestActivity extends BaseActivity {
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
|
||||
deleteBranchFunction(repoOwner, repoName);
|
||||
PullRequestActions.deleteHeadBranch(ctx, repoOwner, repoName, tinyDB.getString("prHeadBranch"), false);
|
||||
|
||||
Toasty.success(ctx, getString(R.string.mergePRSuccessMsg));
|
||||
tinyDB.putBoolean("prMerged", true);
|
||||
@ -201,7 +202,7 @@ public class MergePullRequestActivity extends BaseActivity {
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
|
||||
deleteBranchFunction(repoOwner, repoName);
|
||||
PullRequestActions.deleteHeadBranch(ctx, repoOwner, repoName, tinyDB.getString("prHeadBranch"), false);
|
||||
|
||||
Toasty.success(ctx, getString(R.string.mergePRSuccessMsg));
|
||||
tinyDB.putBoolean("prMerged", true);
|
||||
@ -253,36 +254,6 @@ public class MergePullRequestActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
private void deleteBranchFunction(String repoOwner, String repoName) {
|
||||
|
||||
String branchName = tinyDB.getString("prHeadBranch");
|
||||
|
||||
Call<JsonElement> call = RetrofitClient
|
||||
.getApiInterface(ctx)
|
||||
.deleteBranch(Authorization.get(ctx), repoOwner, repoName, branchName);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
||||
|
||||
if(response.code() == 204) {
|
||||
|
||||
Log.i("deleteBranch", "Branch deleted successfully");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e("onFailure", t.toString());
|
||||
enableProcessButton();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void disableProcessButton() {
|
||||
|
||||
viewBinding.mergeButton.setEnabled(false);
|
||||
|
@ -31,10 +31,10 @@ public class SettingsSecurityActivity extends BaseActivity {
|
||||
|
||||
private View.OnClickListener onClickListener;
|
||||
|
||||
private static final String[] cacheSizeDataList = {"50 MB", "100 MB", "250 MB", "500 MB", "1 GB"};
|
||||
private static String[] cacheSizeDataList;
|
||||
private static int cacheSizeDataSelectedChoice = 0;
|
||||
|
||||
private static final String[] cacheSizeImagesList = {"50 MB", "100 MB", "250 MB", "500 MB", "1 GB"};
|
||||
private static String[] cacheSizeImagesList;
|
||||
private static int cacheSizeImagesSelectedChoice = 0;
|
||||
|
||||
@Override
|
||||
@ -61,6 +61,9 @@ public class SettingsSecurityActivity extends BaseActivity {
|
||||
|
||||
SwitchMaterial switchBiometric = activitySettingsSecurityBinding.switchBiometric;
|
||||
|
||||
cacheSizeDataList = getResources().getStringArray(R.array.cacheSizeList);
|
||||
cacheSizeImagesList = getResources().getStringArray(R.array.cacheSizeList);
|
||||
|
||||
if(!tinyDB.getString("cacheSizeStr").isEmpty()) {
|
||||
|
||||
cacheSizeDataSelected.setText(tinyDB.getString("cacheSizeStr"));
|
||||
|
@ -13,17 +13,24 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
import com.google.gson.JsonElement;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.actions.IssueActions;
|
||||
import org.mian.gitnex.actions.PullRequestActions;
|
||||
import org.mian.gitnex.activities.EditIssueActivity;
|
||||
import org.mian.gitnex.activities.FileDiffActivity;
|
||||
import org.mian.gitnex.activities.MergePullRequestActivity;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.databinding.BottomSheetSingleIssueBinding;
|
||||
import org.mian.gitnex.helpers.AlertDialogs;
|
||||
import org.mian.gitnex.helpers.Authorization;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.Version;
|
||||
import org.mian.gitnex.views.ReactionSpinner;
|
||||
import java.util.Objects;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
@ -50,6 +57,7 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment {
|
||||
TextView copyIssueUrl = bottomSheetSingleIssueBinding.copyIssueUrl;
|
||||
TextView openFilesDiff = bottomSheetSingleIssueBinding.openFilesDiff;
|
||||
TextView mergePullRequest = bottomSheetSingleIssueBinding.mergePullRequest;
|
||||
TextView deletePullRequestBranch = bottomSheetSingleIssueBinding.deletePrHeadBranch;
|
||||
TextView shareIssue = bottomSheetSingleIssueBinding.shareIssue;
|
||||
TextView subscribeIssue = bottomSheetSingleIssueBinding.subscribeIssue;
|
||||
TextView unsubscribeIssue = bottomSheetSingleIssueBinding.unsubscribeIssue;
|
||||
@ -85,9 +93,11 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment {
|
||||
|
||||
if(tinyDB.getBoolean("prMerged") || tinyDB.getString("repoPrState").equals("closed")) {
|
||||
mergePullRequest.setVisibility(View.GONE);
|
||||
deletePullRequestBranch.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
mergePullRequest.setVisibility(View.VISIBLE);
|
||||
deletePullRequestBranch.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.13.0")) {
|
||||
@ -104,6 +114,7 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment {
|
||||
else {
|
||||
|
||||
mergePullRequest.setVisibility(View.GONE);
|
||||
deletePullRequestBranch.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
mergePullRequest.setOnClickListener(v13 -> {
|
||||
@ -112,6 +123,12 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment {
|
||||
dismiss();
|
||||
});
|
||||
|
||||
deletePullRequestBranch.setOnClickListener(v -> {
|
||||
|
||||
PullRequestActions.deleteHeadBranch(ctx, parts[0], parts[1], tinyDB.getString("prHeadBranch"), true);
|
||||
dismiss();
|
||||
});
|
||||
|
||||
openFilesDiff.setOnClickListener(v14 -> {
|
||||
|
||||
startActivity(new Intent(ctx, FileDiffActivity.class));
|
||||
|
@ -58,6 +58,21 @@
|
||||
android:textSize="16sp"
|
||||
app:drawableStartCompat="@drawable/ic_pull_request" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/deletePrHeadBranch"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:focusable="true"
|
||||
android:clickable="true"
|
||||
android:drawablePadding="24dp"
|
||||
android:padding="12dp"
|
||||
android:text="@string/deletePrHeadBranch"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="16sp"
|
||||
app:drawableStartCompat="@drawable/ic_branch" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/editIssue"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -68,4 +68,12 @@
|
||||
<item>@string/pageTitleNotifications</item>
|
||||
<item>@string/navExplore</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="cacheSizeList">
|
||||
<item>50 MB</item>
|
||||
<item>100 MB</item>
|
||||
<item>250 MB</item>
|
||||
<item>500 MB</item>
|
||||
<item>1 GB</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
@ -556,6 +556,10 @@
|
||||
<string name="fileDiffViewHeaderSingle">%1$s File Changed</string>
|
||||
<string name="openFileDiffText">Files Changed</string>
|
||||
<string name="mergePullRequestText">Merge Pull Request</string>
|
||||
<string name="deletePrHeadBranch">Delete head branch</string>
|
||||
<string name="deleteBranchSuccess">Branch deleted successfully</string>
|
||||
<string name="deleteBranchError">Could not delete branch</string>
|
||||
<string name="deleteBranchErrorNotFound">Branch does not exist</string>
|
||||
<string name="mergePullRequestButtonText">Merge</string>
|
||||
<string name="deleteBranchAfterMerge">Delete branch after merge</string>
|
||||
<string name="mergeNoteText">Merge may fail if you are not authorized to merge this Pull Request.</string>
|
||||
|
Loading…
Reference in New Issue
Block a user