summaryrefslogtreecommitdiffstats
path: root/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/ChangeEditApi.java
blob: 9d0275ac19b329064ec9755643a79daea942b087 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.extensions.api.changes;

import com.google.gerrit.extensions.common.EditInfo;
import com.google.gerrit.extensions.restapi.BinaryResult;
import com.google.gerrit.extensions.restapi.NotImplementedException;
import com.google.gerrit.extensions.restapi.RawInput;
import com.google.gerrit.extensions.restapi.RestApiException;
import java.util.Optional;

/**
 * An API for the change edit of a change. A change edit is similar to a patch set and will become
 * one if it is published (by {@link #publish(PublishChangeEditInput)}). Whenever the descriptions
 * below refer to files of a change edit, they actually refer to the files of the Git tree which is
 * represented by the change edit. A change can have at most one change edit at each point in time.
 */
public interface ChangeEditApi {

  /**
   * Retrieves details regarding the change edit.
   *
   * @return an {@code Optional} containing details about the change edit if it exists, or {@code
   *     Optional.empty()}
   * @throws RestApiException if the change edit couldn't be retrieved
   */
  Optional<EditInfo> get() throws RestApiException;

  /**
   * Creates a new change edit. It has exactly the same Git tree as the current patch set of the
   * change.
   *
   * @throws RestApiException if the change edit couldn't be created or a change edit already exists
   */
  void create() throws RestApiException;

  /**
   * Deletes the change edit.
   *
   * @throws RestApiException if the change edit couldn't be deleted or a change edit wasn't present
   */
  void delete() throws RestApiException;

  /**
   * Rebases the change edit on top of the latest patch set of this change.
   *
   * @throws RestApiException if the change edit couldn't be rebased or a change edit wasn't present
   */
  void rebase() throws RestApiException;

  /**
   * Publishes the change edit using default settings. See {@link #publish(PublishChangeEditInput)}
   * for more details.
   *
   * @throws RestApiException if the change edit couldn't be published or a change edit wasn't
   *     present
   */
  void publish() throws RestApiException;

  /**
   * Publishes the change edit. Publishing means that the change edit is turned into a regular patch
   * set of the change.
   *
   * @param publishChangeEditInput a {@code PublishChangeEditInput} specifying the options which
   *     should be applied
   * @throws RestApiException if the change edit couldn't be published or a change edit wasn't
   *     present
   */
  void publish(PublishChangeEditInput publishChangeEditInput) throws RestApiException;

  /**
   * Retrieves the contents of the specified file from the change edit.
   *
   * @param filePath the path of the file
   * @return an {@code Optional} containing the contents of the file as a {@code BinaryResult} if
   *     the file exists within the change edit, or {@code Optional.empty()}
   * @throws RestApiException if the contents of the file couldn't be retrieved or a change edit
   *     wasn't present
   */
  Optional<BinaryResult> getFile(String filePath) throws RestApiException;

  /**
   * Renames a file of the change edit or moves the file to another directory. If the change edit
   * doesn't exist, it will be created based on the current patch set of the change.
   *
   * @param oldFilePath the current file path
   * @param newFilePath the desired file path
   * @throws RestApiException if the file couldn't be renamed
   */
  void renameFile(String oldFilePath, String newFilePath) throws RestApiException;

  /**
   * Restores a file of the change edit to the state in which it was before the patch set on which
   * the change edit is based. This includes the file content as well as the existence or
   * non-existence of the file. If the change edit doesn't exist, it will be created based on the
   * current patch set of the change.
   *
   * @param filePath the path of the file
   * @throws RestApiException if the file couldn't be restored to its previous state
   */
  void restoreFile(String filePath) throws RestApiException;

  /**
   * Modify the contents of the specified file of the change edit. If no content is provided, the
   * content of the file is erased but the file isn't deleted. If the change edit doesn't exist, it
   * will be created based on the current patch set of the change.
   *
   * @param filePath the path of the file which should be modified
   * @param newContent the desired content of the file
   * @throws RestApiException if the content of the file couldn't be modified
   */
  void modifyFile(String filePath, RawInput newContent) throws RestApiException;

  /**
   * Deletes the specified file from the change edit. If the change edit doesn't exist, it will be
   * created based on the current patch set of the change.
   *
   * @param filePath the path fo the file which should be deleted
   * @throws RestApiException if the file couldn't be deleted
   */
  void deleteFile(String filePath) throws RestApiException;

  /**
   * Retrieves the commit message of the change edit.
   *
   * @return the commit message of the change edit
   * @throws RestApiException if the commit message couldn't be retrieved or a change edit wasn't
   *     present
   */
  String getCommitMessage() throws RestApiException;

  /**
   * Modifies the commit message of the change edit. If the change edit doesn't exist, it will be
   * created based on the current patch set of the change.
   *
   * @param newCommitMessage the desired commit message
   * @throws RestApiException if the commit message couldn't be modified
   */
  void modifyCommitMessage(String newCommitMessage) throws RestApiException;

  /**
   * A default implementation which allows source compatibility when adding new methods to the
   * interface.
   */
  class NotImplemented implements ChangeEditApi {
    @Override
    public Optional<EditInfo> get() throws RestApiException {
      throw new NotImplementedException();
    }

    @Override
    public void create() throws RestApiException {
      throw new NotImplementedException();
    }

    @Override
    public void delete() throws RestApiException {
      throw new NotImplementedException();
    }

    @Override
    public void rebase() throws RestApiException {
      throw new NotImplementedException();
    }

    @Override
    public void publish() throws RestApiException {
      throw new NotImplementedException();
    }

    @Override
    public void publish(PublishChangeEditInput publishChangeEditInput) throws RestApiException {
      throw new NotImplementedException();
    }

    @Override
    public Optional<BinaryResult> getFile(String filePath) throws RestApiException {
      throw new NotImplementedException();
    }

    @Override
    public void renameFile(String oldFilePath, String newFilePath) throws RestApiException {
      throw new NotImplementedException();
    }

    @Override
    public void restoreFile(String filePath) throws RestApiException {
      throw new NotImplementedException();
    }

    @Override
    public void modifyFile(String filePath, RawInput newContent) throws RestApiException {
      throw new NotImplementedException();
    }

    @Override
    public void deleteFile(String filePath) throws RestApiException {
      throw new NotImplementedException();
    }

    @Override
    public String getCommitMessage() throws RestApiException {
      throw new NotImplementedException();
    }

    @Override
    public void modifyCommitMessage(String newCommitMessage) throws RestApiException {
      throw new NotImplementedException();
    }
  }
}