Skip to content

Commit

Permalink
Merge branch '6.x' into issue-1067
Browse files Browse the repository at this point in the history
  • Loading branch information
jmini committed Nov 6, 2024
2 parents 8586ea5 + b0e731a commit 3134e9a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
25 changes: 23 additions & 2 deletions gitlab4j-api/src/main/java/org/gitlab4j/api/GitLabApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
public class GitLabApiClient implements AutoCloseable {

protected static final String PRIVATE_TOKEN_HEADER = "PRIVATE-TOKEN";
protected static final String JOB_TOKEN_HEADER = "JOB-TOKEN";
protected static final String SUDO_HEADER = "Sudo";
protected static final String AUTHORIZATION_HEADER = "Authorization";
protected static final String X_GITLAB_TOKEN_HEADER = "X-Gitlab-Token";
Expand Down Expand Up @@ -862,8 +863,8 @@ protected Invocation.Builder invocation(URL url, MultivaluedMap<String, String>
}
}

String authHeader = (tokenType == TokenType.OAUTH2_ACCESS ? AUTHORIZATION_HEADER : PRIVATE_TOKEN_HEADER);
String authValue = (tokenType == TokenType.OAUTH2_ACCESS ? "Bearer " + authToken.get() : authToken.get());
String authHeader = getAuthHeader();
String authValue = getAuthValue();
Invocation.Builder builder = target.request();
if (accept == null || accept.trim().length() == 0) {
builder = builder.header(authHeader, authValue);
Expand All @@ -887,6 +888,26 @@ protected Invocation.Builder invocation(URL url, MultivaluedMap<String, String>
return (builder);
}

private String getAuthValue() {
switch (tokenType) {
case OAUTH2_ACCESS:
return "Bearer " + authToken.get();
default:
return authToken.get();
}
}

private String getAuthHeader() {
switch (tokenType) {
case OAUTH2_ACCESS:
return AUTHORIZATION_HEADER;
case JOB_TOKEN:
return JOB_TOKEN_HEADER;
default:
return PRIVATE_TOKEN_HEADER;
}
}

/**
* Used to set the host URL to be used by OAUTH2 login in GitLabApi.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public String toString() {
private String title;
private Integer userNotesCount;
private String webUrl;
private References references;
private Integer weight;
private Boolean discussionLocked;
private TimeStats timeStats;
Expand Down Expand Up @@ -272,6 +273,14 @@ public void setWebUrl(String webUrl) {
this.webUrl = webUrl;
}

public References getReferences() {
return references;
}

public void setReferences(References references) {
this.references = references;
}

public Integer getWeight() {
return weight;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public interface Constants {
public enum TokenType {
ACCESS,
OAUTH2_ACCESS,
JOB_TOKEN,
PRIVATE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@
"id" : 1,
"name" : "Administrator"
},
"references": {
"short": "#1",
"relative": "#1",
"full": "example/example#1"
},
"severity": "UNKNOWN",
"subscribed": false,
"user_notes_count": 1,
"web_url": "http://example.com/example/example/issues/1",
"web_url": "http://example.com/example/example/-/issues/1",
"confidential": false,
"time_stats": {
"time_estimate": 12600,
Expand Down

0 comments on commit 3134e9a

Please sign in to comment.