Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xdxTao opened this issue Apr 11, 2025 · 0 comments
Open

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

xdxTao opened this issue Apr 11, 2025 · 0 comments
Labels

Comments

@xdxTao
Copy link

xdxTao commented Apr 11, 2025

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

@jmini jmini added the question label Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants