Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
85ad0d84
Commit
85ad0d84
authored
Jan 05, 2018
by
Greg Messner
Browse files
Fixed bug with GitLab where 1mo = 30d (#114).
parent
036fa56d
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/IssuesApi.java
View file @
85ad0d84
...
@@ -33,6 +33,7 @@ import org.gitlab4j.api.GitLabApi.ApiVersion;
...
@@ -33,6 +33,7 @@ import org.gitlab4j.api.GitLabApi.ApiVersion;
import
org.gitlab4j.api.models.Duration
;
import
org.gitlab4j.api.models.Duration
;
import
org.gitlab4j.api.models.Issue
;
import
org.gitlab4j.api.models.Issue
;
import
org.gitlab4j.api.models.TimeStats
;
import
org.gitlab4j.api.models.TimeStats
;
import
org.gitlab4j.api.utils.DurationUtils
;
/**
/**
* This class provides an entry point to all the GitLab API Issue calls.
* This class provides an entry point to all the GitLab API Issue calls.
...
@@ -347,7 +348,8 @@ public class IssuesApi extends AbstractApi implements Constants {
...
@@ -347,7 +348,8 @@ public class IssuesApi extends AbstractApi implements Constants {
throw
new
RuntimeException
(
"issue IID cannot be null"
);
throw
new
RuntimeException
(
"issue IID cannot be null"
);
}
}
GitLabApiForm
formData
=
new
GitLabApiForm
().
withParam
(
"duration"
,
duration
,
true
);
String
durationString
=
(
duration
!=
null
?
DurationUtils
.
toString
(
duration
.
getSeconds
(),
false
)
:
null
);
GitLabApiForm
formData
=
new
GitLabApiForm
().
withParam
(
"duration"
,
durationString
,
true
);
Response
response
=
post
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"projects"
,
projectId
,
"issues"
,
issueIid
,
"time_estimate"
);
Response
response
=
post
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"projects"
,
projectId
,
"issues"
,
issueIid
,
"time_estimate"
);
return
(
response
.
readEntity
(
TimeStats
.
class
));
return
(
response
.
readEntity
(
TimeStats
.
class
));
...
@@ -428,7 +430,8 @@ public class IssuesApi extends AbstractApi implements Constants {
...
@@ -428,7 +430,8 @@ public class IssuesApi extends AbstractApi implements Constants {
throw
new
RuntimeException
(
"issue IID cannot be null"
);
throw
new
RuntimeException
(
"issue IID cannot be null"
);
}
}
GitLabApiForm
formData
=
new
GitLabApiForm
().
withParam
(
"duration"
,
duration
,
true
);
String
durationString
=
(
duration
!=
null
?
DurationUtils
.
toString
(
duration
.
getSeconds
(),
false
)
:
null
);
GitLabApiForm
formData
=
new
GitLabApiForm
().
withParam
(
"duration"
,
durationString
,
true
);
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
.
asMap
(),
"projects"
,
projectId
,
"issues"
,
issueIid
,
"add_spent_time"
);
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
.
asMap
(),
"projects"
,
projectId
,
"issues"
,
issueIid
,
"add_spent_time"
);
return
(
response
.
readEntity
(
TimeStats
.
class
));
return
(
response
.
readEntity
(
TimeStats
.
class
));
...
...
src/main/java/org/gitlab4j/api/utils/DurationUtils.java
View file @
85ad0d84
...
@@ -23,14 +23,28 @@ public class DurationUtils {
...
@@ -23,14 +23,28 @@ public class DurationUtils {
* @return a human readable string representing the duration
* @return a human readable string representing the duration
*/
*/
public
static
final
String
toString
(
int
durationSeconds
)
{
public
static
final
String
toString
(
int
durationSeconds
)
{
return
DurationUtils
.
toString
(
durationSeconds
,
true
);
}
int
months
=
durationSeconds
/
TIME_UNIT_MULTIPLIERS
[
0
];
/**
int
weeks
=
(
durationSeconds
-
months
*
TIME_UNIT_MULTIPLIERS
[
0
])
/
TIME_UNIT_MULTIPLIERS
[
1
];
* Create a human readable duration string from seconds.
int
days
=
(
durationSeconds
-
months
*
TIME_UNIT_MULTIPLIERS
[
0
]
-
weeks
*
TIME_UNIT_MULTIPLIERS
[
1
])
/
TIME_UNIT_MULTIPLIERS
[
2
];
*
int
seconds
=
durationSeconds
-
(
months
*
TIME_UNIT_MULTIPLIERS
[
0
])
-
(
weeks
*
TIME_UNIT_MULTIPLIERS
[
1
])
-
(
days
*
TIME_UNIT_MULTIPLIERS
[
2
]);
* @param durationSeconds the total number of seconds in the duration
* @return a human readable string representing the duration
*/
public
static
final
String
toString
(
int
durationSeconds
,
boolean
includeMonths
)
{
int
seconds
=
durationSeconds
;
int
months
=
(
includeMonths
?
seconds
/
TIME_UNIT_MULTIPLIERS
[
0
]
:
0
);
seconds
-=
months
*
TIME_UNIT_MULTIPLIERS
[
0
];
int
weeks
=
seconds
/
TIME_UNIT_MULTIPLIERS
[
1
];
seconds
-=
weeks
*
TIME_UNIT_MULTIPLIERS
[
1
];
int
days
=
seconds
/
TIME_UNIT_MULTIPLIERS
[
2
];
seconds
-=
days
*
TIME_UNIT_MULTIPLIERS
[
2
];
int
hours
=
seconds
/
3600
;
int
hours
=
seconds
/
3600
;
int
minutes
=
(
seconds
%
3600
)
/
60
;
seconds
-=
hours
*
3600
;
seconds
=
seconds
%
60
;
int
minutes
=
seconds
/
60
;
seconds
-=
minutes
*
60
;
StringBuilder
buf
=
new
StringBuilder
();
StringBuilder
buf
=
new
StringBuilder
();
if
(
months
>
0
)
{
if
(
months
>
0
)
{
...
...
src/test/java/org/gitlab4j/api/TestDuration.java
View file @
85ad0d84
...
@@ -102,5 +102,11 @@ public class TestDuration {
...
@@ -102,5 +102,11 @@ public class TestDuration {
duration
=
DurationUtils
.
toString
(
60
*
60
*
8
*
5
*
4
*
3
+
60
*
60
*
8
*
2
+
60
*
60
*
3
+
60
*
6
+
8
);
duration
=
DurationUtils
.
toString
(
60
*
60
*
8
*
5
*
4
*
3
+
60
*
60
*
8
*
2
+
60
*
60
*
3
+
60
*
6
+
8
);
assertEquals
(
"3mo2d3h6m8s"
,
duration
);
assertEquals
(
"3mo2d3h6m8s"
,
duration
);
duration
=
DurationUtils
.
toString
(
60
*
60
*
8
*
5
*
5
+
60
*
60
*
8
*
2
+
60
*
60
*
3
+
60
*
4
+
5
,
false
);
assertEquals
(
"5w2d3h4m5s"
,
duration
);
duration
=
DurationUtils
.
toString
(
60
*
60
*
8
*
5
*
4
*
3
+
60
*
60
*
8
*
2
+
60
*
60
*
3
+
60
*
6
+
8
,
false
);
assertEquals
(
"12w2d3h6m8s"
,
duration
);
}
}
}
}
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