Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Lukas Wiest
unified-ticketing
Commits
b841acdd
Unverified
Commit
b841acdd
authored
Nov 04, 2020
by
Lukas Wiest
🚂
Browse files
feat: import first state of library code
parent
dd0df320
Changes
23
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/hft/unifiedticketing/systems/gitlab/GitlabTicketResponse.java
0 → 100644
View file @
b841acdd
package
de.hft.unifiedticketing.systems.gitlab
;
import
java.util.List
;
import
java.util.Set
;
public
class
GitlabTicketResponse
{
protected
GitlabTicketResponse
()
{
}
public
List
<
Assignee
>
assignees
;
public
String
description
;
public
int
iid
;
public
Set
<
String
>
labels
;
public
String
state
;
public
String
title
;
protected
static
class
Assignee
{
public
int
id
;
public
String
name
;
public
String
username
;
}
}
src/main/java/de/hft/unifiedticketing/systems/gitlab/GitlabTicketSystem.java
0 → 100644
View file @
b841acdd
package
de.hft.unifiedticketing.systems.gitlab
;
import
de.hft.unifiedticketing.core.Logging
;
import
de.hft.unifiedticketing.core.TicketSystem
;
import
de.hft.unifiedticketing.exceptions.AssertionException
;
import
de.hft.unifiedticketing.exceptions.UnifiedticketingException
;
import
java.util.List
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
GitlabTicketSystem
extends
TicketSystem
<
GitlabTicket
,
GitlabTicketSystem
,
GitlabTicketBuilder
,
GitlabFilter
>
{
private
static
Logger
logger
=
Logging
.
getLogger
(
TicketSystem
.
class
.
getName
());
/**
* creates a new instance of this class from an uri.<br/>
* <br/>
* <b>Attention:</b> This method should not be called from the enduser!<br/>
* Instead call the same method from {@link TicketSystem}.<br/>
* To call this method directly, the uri has to be shortend by the "unifiedticketing:gitlab:" part.
* @param uri gitlab specific part of full uri
* @return new gitlab ticket instance
*/
public
static
GitlabTicketSystem
fromUri
(
String
uri
)
{
Matcher
matcher
=
Pattern
.
compile
(
"^((http|https):\\/\\/)?(.*(:[0-9]+)?):([0-9]+)(:(.*))?$"
).
matcher
(
uri
);
if
(!
matcher
.
matches
())
{
logger
.
log
(
Level
.
SEVERE
,
"uri didn't match regex"
);
throw
new
AssertionException
(
"uri didn't match regex"
);
}
GitlabTicketSystemBuilder
builder
=
new
GitlabTicketSystemBuilder
();
if
(
matcher
.
group
(
2
)
!=
null
&&
matcher
.
group
(
2
).
length
()
>
0
)
{
if
(
matcher
.
group
(
2
).
equalsIgnoreCase
(
"http"
))
builder
.
withHttp
();
else
builder
.
withHttps
();
}
if
(
matcher
.
group
(
3
)
==
null
||
matcher
.
group
(
3
).
length
()
==
0
)
{
logger
.
log
(
Level
.
SEVERE
,
"no base url identified in uri"
);
throw
new
AssertionException
(
"no base url found"
);
}
builder
.
withBaseUrl
(
matcher
.
group
(
3
));
if
(
matcher
.
group
(
5
)
==
null
||
matcher
.
group
(
5
).
length
()
==
0
)
{
logger
.
log
(
Level
.
SEVERE
,
"no project id identified in uri"
);
throw
new
AssertionException
(
"no project id found"
);
}
builder
.
withProjectId
(
matcher
.
group
(
5
));
if
(
matcher
.
group
(
6
)
==
null
||
matcher
.
group
(
6
).
length
()
==
0
)
{
logger
.
log
(
Level
.
INFO
,
"no api key identified in uri, creating anonymous instance"
);
}
else
{
builder
.
withApiKey
(
matcher
.
group
(
7
));
}
return
builder
.
build
();
}
protected
GitlabTicketSystem
()
{
logger
.
log
(
Level
.
FINEST
,
"GitLab Ticketsystem created"
);
}
/**
* starts builder process for a new gitlab ticket
*/
@Override
public
GitlabTicketBuilder
createTicket
()
{
return
new
GitlabTicketBuilder
(
this
);
}
/**
* starts filter builder to define constraints and then request those tickets
*/
@Override
public
GitlabFilter
find
()
{
return
new
GitlabFilter
(
this
);
}
// @Override
// public List<GitlabTicket> getAllTickets()
// {
// logger.log(Level.FINER, "redirecting request to find method");
// return this.find()
// .get();
// }
/**
* This requests a dedicated ticket by it's id.
* It internally calls {@link #find()}, set's the id as filter
* and ensure to get exactly one element as answer.
* @param id ticket id to request
* @throws UnifiedticketingException if more or less than one element in the response
*/
@Override
public
GitlabTicket
getTicketById
(
String
id
)
{
logger
.
log
(
Level
.
FINER
,
"redirecting request to find method"
);
List
<
GitlabTicket
>
ret
=
this
.
find
()
.
withId
(
id
)
.
get
();
if
(
ret
==
null
)
return
null
;
else
if
(
ret
.
size
()
!=
1
)
throw
new
UnifiedticketingException
(
"more or less than 1 dedicated ticket found"
);
else
return
ret
.
get
(
0
);
}
@Override
public
boolean
hasAssigneeSupport
()
{
return
true
;
}
@Override
public
boolean
hasDefaultPagination
()
{
return
true
;
}
@Override
public
boolean
hasLabelSupport
()
{
return
true
;
}
@Override
public
boolean
hasPaginationSupport
()
{
return
true
;
}
@Override
public
boolean
hasReturnNullOnErrorSupport
()
{
return
true
;
}
}
src/main/java/de/hft/unifiedticketing/systems/gitlab/GitlabTicketSystemBuilder.java
0 → 100644
View file @
b841acdd
package
de.hft.unifiedticketing.systems.gitlab
;
import
de.hft.unifiedticketing.core.Logging
;
import
de.hft.unifiedticketing.core.TicketSystemBuilder
;
import
de.hft.unifiedticketing.exceptions.AssertionException
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
public
class
GitlabTicketSystemBuilder
extends
TicketSystemBuilder
<
GitlabTicketSystemBuilder
,
GitlabTicketSystem
>
{
private
static
Logger
logger
=
Logging
.
getLogger
(
GitlabTicketSystemBuilder
.
class
.
getName
());
protected
String
apiKey
;
protected
String
apiVersion
;
protected
int
projectId
;
protected
boolean
https
;
/**
* starts builder process for a {@link GitlabTicketSystem} instance
*/
public
GitlabTicketSystemBuilder
()
{
super
();
apiVersion
=
"v4"
;
projectId
=
-
1
;
https
=
true
;
logger
.
log
(
Level
.
FINEST
,
"Builder for Gitlab System instance started"
);
}
/**
* defines api-key to be used for requests<br/>
* <br/>
* if you don't specify an api-key, all requests will be without credentials
* @param apiKey your user specific
* @return this ticket system builder
*/
public
GitlabTicketSystemBuilder
withApiKey
(
String
apiKey
)
{
this
.
apiKey
=
apiKey
;
logger
.
log
(
Level
.
FINEST
,
"set api key"
);
return
this
;
}
/**
* set protocol to http (no transport security!)
* @return this ticket system builder
*/
public
GitlabTicketSystemBuilder
withHttp
()
{
this
.
https
=
false
;
logger
.
log
(
Level
.
FINEST
,
"set http"
);
return
this
;
}
/**
* set protocol to https (enabled transport security)<br/>
* this is the default
* @return this ticket system builder
*/
public
GitlabTicketSystemBuilder
withHttps
()
{
this
.
https
=
true
;
logger
.
log
(
Level
.
FINEST
,
"set https"
);
return
this
;
}
/**
* set project id the instance should work in
* @return this ticket system builder
*/
public
GitlabTicketSystemBuilder
withProjectId
(
int
projectId
)
{
this
.
projectId
=
projectId
;
logger
.
log
(
Level
.
FINEST
,
"set project id to "
+
this
.
projectId
);
return
this
;
}
/**
* set project id the instance should work in
* @return this ticket system builder
* @throws AssertionException if {@code projectId} is not parsable to as integer
*/
public
GitlabTicketSystemBuilder
withProjectId
(
String
projectId
)
{
try
{
return
this
.
withProjectId
(
Integer
.
parseInt
(
projectId
));
}
catch
(
NumberFormatException
e
)
{
logger
.
log
(
Level
.
SEVERE
,
String
.
format
(
"given String is not parsable to an integer projectId: %s"
,
projectId
));
throw
new
AssertionException
(
e
);
}
}
/**
* builds a new gitlab ticket system instance with the given information.<br/>
* <br/>
* The minimum builder methods needed, are {@link #withBaseUrl} and {@link #withProjectId}.
* @return new {@link GitlabTicketSystem} instance
* @throws AssertionException if {@link #withBaseUrl} or {@link #withProjectId} not called beforehand
*/
@Override
public
GitlabTicketSystem
build
()
{
if
(
baseUrl
==
null
||
projectId
==
-
1
)
{
logger
.
log
(
Level
.
SEVERE
,
"to build a GitlabTicketSystem instance at least a base url and projectId are needed!"
);
throw
new
AssertionException
(
"baseUrl or projectId are missing"
);
}
GitlabTicketSystem
system
=
new
GitlabTicketSystem
();
system
.
baseUrl
=
String
.
format
(
"%s://%s/api/%s/projects/%d"
,
(
this
.
https
)
?
"https"
:
"http"
,
this
.
baseUrl
,
this
.
apiVersion
,
this
.
projectId
);
system
.
apiKey
=
apiKey
;
logger
.
log
(
Level
.
FINEST
,
"created instance of "
+
system
.
getClass
().
getSimpleName
()
+
" with baseUrl "
+
system
.
baseUrl
);
return
system
;
}
}
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment