Skip to content
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

Different types of branch.id and approvalRule.protectedBranchIds #206

Closed
wrbbz opened this issue Jan 31, 2023 · 1 comment
Closed

Different types of branch.id and approvalRule.protectedBranchIds #206

wrbbz opened this issue Jan 31, 2023 · 1 comment
Labels
kind/bug Some behavior is incorrect or out of spec

Comments

@wrbbz
Copy link

wrbbz commented Jan 31, 2023

What happened?

I am trying to get default branch of the project with:

const branchId = gitlab.getBranch({
  name: project.defaultBranch,
  project: project.pathWithNamespace,
}).then(branch => branch.id);

And after that to set it to projectApprovalRule:

const projectApproval = new gitlab.ProjectApprovalRule(`${repoName}-${ruleName}`, {
  approvalsRequired: 1,
  project: pulumi.all([project.id]).apply(([project]) => `${project}`),
  name: rule.name,
  userIds: rule.userIds,
  groupIds: rule.groupIds,
  protectedBranchIds: [branchId],
});

The problem is branchId has type string, while ProjectApprovalRule requires array of numbers.
The solution given in #28 does not work due to the fact that branchId looks like: project.pathWithNamespace: project.defaultBranch which could not be converted to number.

Expected Behavior

The expected behavior is an ability to pass an output of getBranch to ProjectApprovalRule creation

Steps to reproduce

It is enough to call getBranch method and pass the output to ProjectApprovalRule

Output of pulumi about

❯ pulumi about
CLI
Version      3.53.1
Go Version   go1.19.5
Go Compiler  gc

Plugins
NAME    VERSION
gitlab  4.9.0
nodejs  unknown

Host
OS       darwin
Version  13.1
Arch     x86_64

This project is written in nodejs: executable='/usr/local/bin/node' version='v19.5.0'

Current Stack: prd

TYPE                                                  URN
pulumi:pulumi:Stack                                   urn:pulumi:prd::gitlab-approval-rules::pulumi:pulumi:Stack::gitlab-approval-rules-prd
pulumi:providers:gitlab                               urn:pulumi:prd::gitlab-approval-rules::pulumi:providers:gitlab::default_4_9_0
gitlab:index/projectApprovalRule:ProjectApprovalRule  urn:pulumi:prd::gitlab-approval-rules::gitlab:index/projectApprovalRule:ProjectApprovalRule::platform-346-platform-approvals
gitlab:index/projectApprovalRule:ProjectApprovalRule  urn:pulumi:prd::gitlab-approval-rules::gitlab:index/projectApprovalRule:ProjectApprovalRule::rds-mysql-451-team-lead
gitlab:index/projectApprovalRule:ProjectApprovalRule  urn:pulumi:prd::gitlab-approval-rules::gitlab:index/projectApprovalRule:ProjectApprovalRule::csmoney-239-tech-review
gitlab:index/projectApprovalRule:ProjectApprovalRule  urn:pulumi:prd::gitlab-approval-rules::gitlab:index/projectApprovalRule:ProjectApprovalRule::csmoney-239-team-lead


Found no pending operations associated with prd

Backend
Name           wrbbzBook.local
URL            ${secretUrl}
User           arseniyzorin
Organizations

Dependencies:
NAME            VERSION
@pulumi/gitlab  4.9.0
@pulumi/pulumi  3.53.1
@types/node     16.18.11

Additional context

The GitLab API itself says that branch id has string type (URL-encoded name of the branch).

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@wrbbz wrbbz added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Jan 31, 2023
@wrbbz
Copy link
Author

wrbbz commented Jan 31, 2023

Nvm. Found out, what I am doing wrong.
There are protected branches and ordinary branches.
To get ids in numbers for protected branches, you have to call getProjectProtectedBranch and use its output

@wrbbz wrbbz closed this as completed Jan 31, 2023
@AaronFriel AaronFriel removed the needs-triage Needs attention from the triage team label Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

No branches or pull requests

2 participants