gitlab4j-api icon indicating copy to clipboard operation
gitlab4j-api copied to clipboard

Hello, I want to know if GitLabApi has thread safety issues

Open xdxTao opened this issue 10 months ago • 0 comments

This is how I use it now

try(GitLabApi gitLabApi = new GitLabApi(rootUrl, param.getGitlabToken())) {
    MergeRequestParams mrParams = new MergeRequestParams()
            .withSourceBranch(param.getSourceBranch())
            .withTargetBranch(param.getTargetBranch())
            .withTitle(param.getTitle())
            .withDescription(param.getDescription())
            .withLabels(param.getLabels());
    MergeRequest  mergeRequest = gitLabApi.getMergeRequestApi().createMergeRequest(param.getGitProjectId().longValue(), mrParams);
    return GitlabFormatUtils.buildGitlabMergeRequest(mergeRequest);
} catch (GitLabApiException e) {
    log.error("创建MergeRequest失败,param:{}", param, e);
    throw new ServiceException("创建gitlab MergeRequest失败");
}

I want to change it to the following, but I am worried about thread safety issues

@Configuration
public class GitLabSdkConfig {


    @Value("${gitlab.rootUrl}")
    private String rootUrl;

    @Value("${gitlab.devopsToken}")
    private String devopsToken;

    @Bean
    public GitLabApi initGitLabApi() {

        return new GitLabApi(rootUrl, devopsToken);
    }

}
@Resource
private GitLabApi gitLabApi;


try {
    MergeRequestParams mrParams = new MergeRequestParams()
            .withSourceBranch(param.getSourceBranch())
            .withTargetBranch(param.getTargetBranch())
            .withTitle(param.getTitle())
            .withDescription(param.getDescription())
            .withLabels(param.getLabels());

    MergeRequest mergeRequest = gitLabApi.getMergeRequestApi().createMergeRequest(param.getGitProjectId().longValue(), mrParams);
    return GitlabFormatUtils.buildGitlabMergeRequest(mergeRequest);
} catch (GitLabApiException e) {
    log.error("创建MergeRequest失败,param:{}", param, e);
    throw new ServiceException("创建gitlab MergeRequest失败");
}

thanks for your answer

xdxTao avatar Apr 11 '25 08:04 xdxTao