Skip to content

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

@xdxTao

Description

@xdxTao

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions