Repository: diggerhq/digger
Pull request #420 (2023-06-29 16:09:55)

support configurable digger organisation for digger rbac
- support configurable digger organisation for digger rbac
- improvements to allow for setting of organisation
- 


Patch:
diff --git a/action.yml b/action.yml
index c7f1d88a..9f1f908f 100644
--- a/action.yml
+++ b/action.yml
@@ -78,6 +78,9 @@ inputs:
     description: Digger hostname
     required: false
     default: 'https://cloud.digger.dev'
+  digger-organisation:
+    description: The name of your digger organisation
+    required: false
   setup-tfenv:
     description: Setup tfenv
     required: false
@@ -188,6 +191,7 @@ runs:
         ACTIVATE_VENV: ${{ inputs.setup-checkov == 'true' }}
         DISABLE_LOCKING: ${{ inputs.disable-locking == 'true' }}
         DIGGER_TOKEN: ${{ inputs.digger-token }}
+        DIGGER_ORGANISATION: ${{ inputs.digger-organisation }}
         DIGGER_HOSTNAME: ${{ inputs.digger-hostname }}
         ACCUMULATE_PLANS: ${{ inputs.post-plans-as-one-comment == 'true' }}
         REPORTING_STRATEGY: ${{ inputs.reporting-strategy }}
diff --git a/cmd/digger/main.go b/cmd/digger/main.go
index 26b8c8c2..edf03b6c 100644
--- a/cmd/digger/main.go
+++ b/cmd/digger/main.go
@@ -333,11 +333,15 @@ func main() {
 	}
 	var policyChecker core_policy.Checker
 	if os.Getenv("DIGGER_TOKEN") != "" {
+		if os.Getenv("DIGGER_ORGANISATION") == "" {
+			log.Fatalf("Token specified but missing organisation: DIGGER_ORGANISATION. Please set this value in action configuration.")
+		}
 		policyChecker = policy.DiggerPolicyChecker{
 			PolicyProvider: &policy.DiggerHttpPolicyProvider{
-				DiggerHost: os.Getenv("DIGGER_HOSTNAME"),
-				AuthToken:  os.Getenv("DIGGER_TOKEN"),
-				HttpClient: http.DefaultClient,
+				DiggerHost:         os.Getenv("DIGGER_HOSTNAME"),
+				DiggerOrganisation: os.Getenv("DIGGER_ORGANISATION"),
+				AuthToken:          os.Getenv("DIGGER_TOKEN"),
+				HttpClient:         http.DefaultClient,
 			}}
 	} else {
 		policyChecker = policy.NoOpPolicyChecker{}
diff --git a/go.sum b/go.sum
index 882e1d42..70fb2e49 100644
--- a/go.sum
+++ b/go.sum
@@ -29,8 +29,6 @@ github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRB
 github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
 github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q=
 github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
-github.com/aws/aws-sdk-go v1.44.282 h1:ZPB9QhwxmMIEC8ja0DdFowOl5fODWaZ6s2cZ40fx6r8=
-github.com/aws/aws-sdk-go v1.44.282/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
 github.com/aws/aws-sdk-go v1.44.291 h1:JVgIyvdYm/A6iCHD0UIS/Hvu/GVHjpW7bN3mwG6sHlU=
 github.com/aws/aws-sdk-go v1.44.291/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
 github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
@@ -44,7 +42,6 @@ github.com/caarlos0/env/v8 v8.0.0/go.mod h1:7K4wMY9bH0esiXSSHlfHLX5xKGQMnkH5Fk4T
 github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4=
 github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
 github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
-github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
 github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
 github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
 github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
@@ -74,7 +71,6 @@ github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
 github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
 github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
 github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
-github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
 github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
 github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
 github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
@@ -83,7 +79,6 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre
 github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
 github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
 github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
-github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
 github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
 github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
@@ -118,8 +113,6 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
 github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
 github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
-github.com/google/go-github/v53 v53.1.0 h1:mKJnR9lzZwD1fvbp27aK1i6rxyAbycWsXlN+r9JKPqM=
-github.com/google/go-github/v53 v53.1.0/go.mod h1:XhFRObz+m/l+UCm9b7KSIC3lT3NWSXGt7mOsAWEloao=
 github.com/google/go-github/v53 v53.2.0 h1:wvz3FyF53v4BK+AsnvCmeNhf8AkTaeh2SoYu/XUvTtI=
 github.com/google/go-github/v53 v53.2.0/go.mod h1:XhFRObz+m/l+UCm9b7KSIC3lT3NWSXGt7mOsAWEloao=
 github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
@@ -146,9 +139,6 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y
 github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
 github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
 github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
-github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
-github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
-github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
 github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
 github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
 github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -159,9 +149,6 @@ github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfr
 github.com/microsoft/azure-devops-go-api/azuredevops v1.0.0-b5 h1:YH424zrwLTlyHSH/GzLMJeu5zhYVZSx5RQxGKm1h96s=
 github.com/microsoft/azure-devops-go-api/azuredevops v1.0.0-b5/go.mod h1:PoGiBqKSQK1vIfQ+yVaFcGjDySHvym6FM1cNYnwzbrY=
 github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg=
-github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
-github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
-github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
 github.com/open-policy-agent/opa v0.53.1 h1:APN8iA7Txgel13kSkc6S8dbUulydiPojXt6iyubmB7Q=
 github.com/open-policy-agent/opa v0.53.1/go.mod h1:j3wl8FqSz/+u33Scl72Ms2wxkZx4yZPdqSCrOqBqdsA=
 github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
@@ -196,8 +183,6 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
 github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
 github.com/tchap/go-patricia/v2 v2.3.1 h1:6rQp39lgIYZ+MHmdEq4xzuk1t7OdC35z/xm0BGhTkes=
 github.com/tchap/go-patricia/v2 v2.3.1/go.mod h1:VZRHKAb53DLaG+nA9EaYYiaEx6YztwDlLElMsnSHD4k=
-github.com/xanzy/go-gitlab v0.85.0 h1:E/wjnsd/mM5kV6O9y5+i6zxjx+wfAwa97sgcT1ETNwk=
-github.com/xanzy/go-gitlab v0.85.0/go.mod h1:5ryv+MnpZStBH8I/77HuQBsMbBGANtVpLWC15qOjWAw=
 github.com/xanzy/go-gitlab v0.86.0 h1:jR8V9cK9jXRQDb46KOB20NCF3ksY09luaG0IfXE6p7w=
 github.com/xanzy/go-gitlab v0.86.0/go.mod h1:5ryv+MnpZStBH8I/77HuQBsMbBGANtVpLWC15qOjWAw=
 github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
diff --git a/pkg/core/policy/policy.go b/pkg/core/policy/policy.go
index a5d5dadc..296eac52 100644
--- a/pkg/core/policy/policy.go
+++ b/pkg/core/policy/policy.go
@@ -1,9 +1,11 @@
 package policy
 
+import "digger/pkg/ci"
+
 type Provider interface {
 	GetPolicy(namespace string, projectname string) (string, error)
 }
 
 type Checker interface {
-	Check(organisation string, namespace string, projectname string, command string, requestedBy string) (bool, error)
+	Check(ciService ci.CIService, SCMOrganisation string, SCMrepository string, projectname string, command string, requestedBy string) (bool, error)
 }
diff --git a/pkg/digger/digger.go b/pkg/digger/digger.go
index f97ac849..e8370d9b 100644
--- a/pkg/digger/digger.go
+++ b/pkg/digger/digger.go
@@ -15,12 +15,13 @@ import (
 	"digger/pkg/usage"
 	"errors"
 	"fmt"
-	"github.com/dominikbraun/graph"
 	"log"
 	"os"
 	"path"
 	"strings"
 	"time"
+
+	"github.com/dominikbraun/graph"
 )
 
 type CIName string
@@ -75,7 +76,9 @@ func RunCommandsPerProject(
 ) (bool, bool, error) {
 	appliesPerProject := make(map[string]bool)
 
-	organisation := strings.Split(projectNamespace, "/")[0]
+	splits := strings.Split(projectNamespace, "/")
+	SCMOrganisation := splits[0]
+	SCMrepository := splits[1]
 
 	commandsPerProject = SortedCommandsByDependency(commandsPerProject, dependencyGraph)
 
@@ -83,7 +86,7 @@ func RunCommandsPerProject(
 		for _, command := range projectCommands.Commands {
 			fmt.Printf("Running '%s' for project '%s'\n", command, projectCommands.ProjectName)
 
-			allowedToPerformCommand, err := policyChecker.Check(organisation, projectNamespace, projectCommands.ProjectName, command, requestedBy)
+			allowedToPerformCommand, err := policyChecker.Check(ciService, SCMOrganisation, SCMrepository, projectCommands.ProjectName, command, requestedBy)
 
 			if err != nil {
 				return false, false, fmt.Errorf("error checking policy: %v", err)
@@ -264,28 +267,39 @@ func SortedCommandsByDependency(project []models.ProjectCommand, dependencyGraph
 
 func MergePullRequest(ciService ci.CIService, prNumber int) {
 	time.Sleep(5 * time.Second)
-	combinedStatus, err := ciService.GetCombinedPullRequestStatus(prNumber)
 
+	// Check if it was manually merged
+	isMerged, err := ciService.IsMerged(prNumber)
 	if err != nil {
-		log.Fatalf("failed to get combined status, %v", err)
+		log.Fatalf("error checking if PR is merged: %v", err)
 	}
 
-	if combinedStatus != "success" {
-		log.Fatalf("PR is not mergeable. Status: %v", combinedStatus)
-	}
+	if !isMerged {
+		combinedStatus, err := ciService.GetCombinedPullRequestStatus(prNumber)
 
-	prIsMergeable, err := ciService.IsMergeable(prNumber)
+		if err != nil {
+			log.Fatalf("failed to get combined status, %v", err)
+		}
 
-	if err != nil {
-		log.Fatalf("failed to check if PR is mergeable, %v", err)
-	}
+		if combinedStatus != "success" {
+			log.Fatalf("PR is not mergeable. Status: %v", combinedStatus)
+		}
 
-	if !prIsMergeable {
-		log.Fatalf("PR is not mergeable")
-	}
+		prIsMergeable, err := ciService.IsMergeable(prNumber)
 
-	err = ciService.MergePullRequest(prNumber)
-	if err != nil {
-		log.Fatalf("failed to merge PR, %v", err)
+		if err != nil {
+			log.Fatalf("failed to check if PR is mergeable, %v", err)
+		}
+
+		if !prIsMergeable {
+			log.Fatalf("PR is not mergeable")
+		}
+
+		err = ciService.MergePullRequest(prNumber)
+		if err != nil {
+			log.Fatalf("failed to merge PR, %v", err)
+		}
+	} else {
+	   log.Printf("PR is already merged, skipping merge step")
 	}
 }
diff --git a/pkg/policy/policy.go b/pkg/policy/policy.go
index 26b5fb23..853c3216 100644
--- a/pkg/policy/policy.go
+++ b/pkg/policy/policy.go
@@ -8,28 +8,29 @@ import (
 	"github.com/open-policy-agent/opa/rego"
 	"io"
 	"net/http"
-	"strings"
 )
 
 type PolicyProvider interface {
-	GetPolicy(organisation string, namespace string, projectname string) (string, error)
+	GetPolicy(organisation string, repository string, projectname string) (string, error)
+	GetOrganisation() string
 }
 
 type DiggerHttpPolicyProvider struct {
-	DiggerHost string
-	AuthToken  string
-	HttpClient *http.Client
+	DiggerHost         string
+	DiggerOrganisation string
+	AuthToken          string
+	HttpClient         *http.Client
 }
 
 type NoOpPolicyChecker struct {
 }
 
-func (p NoOpPolicyChecker) Check(_ string, _ string, _ string, _ string, _ string) (bool, error) {
+func (p NoOpPolicyChecker) Check(_ ci.CIService, _ string, _ string, _ string, _ string, _ string) (bool, error) {
 	return true, nil
 }
 
-func (p *DiggerHttpPolicyProvider) getPolicyForOrganisation(organisation string) (string, *http.Response, error) {
-
+func getPolicyForOrganisation(p *DiggerHttpPolicyProvider) (string, *http.Response, error) {
+	organisation := p.DiggerOrganisation
 	req, err := http.NewRequest("GET", p.DiggerHost+"/orgs/"+organisation+"/access-policy", nil)
 	if err != nil {
 		return "", nil, err
@@ -49,10 +50,8 @@ func (p *DiggerHttpPolicyProvider) getPolicyForOrganisation(organisation string)
 	return string(body), resp, nil
 }
 
-func (p *DiggerHttpPolicyProvider) getPolicyForNamespace(namespace string, projectName string) (string, *http.Response, error) {
-
-	// fetch RBAC policies for projectfrom Digger API
-	namespace = strings.ReplaceAll(namespace, "/", "-")
+func getPolicyForNamespace(p *DiggerHttpPolicyProvider, namespace string, projectName string) (string, *http.Response, error) {
+	// fetch RBAC policies for project from Digger API
 	req, err := http.NewRequest("GET", p.DiggerHost+"/repos/"+namespace+"/projects/"+projectName+"/access-policy", nil)
 
 	if err != nil {
@@ -75,15 +74,17 @@ func (p *DiggerHttpPolicyProvider) getPolicyForNamespace(namespace string, proje
 }
 
 // GetPolicy fetches policy for particular project,  if not found then it will fallback to org level policy
-func (p *DiggerHttpPolicyProvider) GetPolicy(organisation string, namespace string, projectName string) (string, error) {
-	content, resp, err := p.getPolicyForNamespace(namespace, projectName)
+func (p *DiggerHttpPolicyProvider) GetPolicy(organisation string, repo string, projectName string) (string, error) {
+	namespace := fmt.Sprintf("%v-%v", organisation, repo)
+	content, resp, err := getPolicyForNamespace(p, namespace, projectName)
 	if err != nil {
 		return "", err
 	}
-	if resp.StatusCode == 200 {
+
+	if resp.StatusCode == 200 && content != "" {
 		return content, nil
 	} else if resp.StatusCode == 404 {
-		content, resp, err := p.getPolicyForOrganisation(organisation)
+		content, resp, err := getPolicyForOrganisation(p)
 		if err != nil {
 			return "", err
 		}
@@ -99,15 +100,18 @@ func (p *DiggerHttpPolicyProvider) GetPolicy(organisation string, namespace stri
 	}
 }
 
+func (p *DiggerHttpPolicyProvider) GetOrganisation() string {
+	return p.DiggerOrganisation
+}
+
 type DiggerPolicyChecker struct {
 	PolicyProvider PolicyProvider
-	ciService      ci.CIService
 }
 
-func (p DiggerPolicyChecker) Check(organisation string, namespace string, projectName string, command string, requestedBy string) (bool, error) {
-	policy, err := p.PolicyProvider.GetPolicy(organisation, namespace, projectName)
-
-	teams, err := p.ciService.GetUserTeams(organisation, requestedBy)
+func (p DiggerPolicyChecker) Check(ciService ci.CIService, SCMOrganisation string, SCMrepository string, projectName string, command string, requestedBy string) (bool, error) {
+	organisation := p.PolicyProvider.GetOrganisation()
+	policy, err := p.PolicyProvider.GetPolicy(organisation, SCMrepository, projectName)
+	teams, err := ciService.GetUserTeams(SCMOrganisation, requestedBy)
 	if err != nil {
 		fmt.Printf("Error while fetching user teams for CI service: %v", err)
 		return false, err
diff --git a/pkg/utils/mocks.go b/pkg/utils/mocks.go
index bc05bd22..b299a917 100644
--- a/pkg/utils/mocks.go
+++ b/pkg/utils/mocks.go
@@ -44,7 +44,7 @@ func (lock *MockLock) GetLock(resource string) (*int, error) {
 type MockPolicyChecker struct {
 }
 
-func (t MockPolicyChecker) Check(organisation string, namespace string, projectname string, command string, requestedBy string) (bool, error) {
+func (t MockPolicyChecker) Check(ciService ci.CIService, SCMOrganisation string, SCMrepository string, projectName string, command string, requestedBy string) (bool, error) {
 	return false, nil
 }
 


Test patch:
diff --git a/cmd/digger/main_test.go b/cmd/digger/main_test.go
index 13b13fa5..a878f9d7 100644
--- a/cmd/digger/main_test.go
+++ b/cmd/digger/main_test.go
@@ -889,7 +889,7 @@ func TestGitHubNewPullRequestContext(t *testing.T) {
 		PrNumber:  prNumber,
 	}
 	commandsToRunPerProject, _, err := github.ConvertGithubEventToCommands(ghEvent, impactedProjects, requestedProject, map[string]configuration.Workflow{})
-	_, _, err = digger.RunCommandsPerProject(commandsToRunPerProject, &depGraph, context.RepositoryOwner, context.Repository, eventName, prNumber, prManager, lock, reporter, planStorage, policyChecker, "")
+	_, _, err = digger.RunCommandsPerProject(commandsToRunPerProject, &depGraph, context.Repository, context.Repository, eventName, prNumber, prManager, lock, reporter, planStorage, policyChecker, "")
 
 	assert.NoError(t, err)
 	if err != nil {
@@ -919,10 +919,7 @@ func TestGitHubNewCommentContext(t *testing.T) {
 	policyChecker := &utils.MockPolicyChecker{}
 
 	commandsToRunPerProject, _, err := github.ConvertGithubEventToCommands(ghEvent, impactedProjects, requestedProject, map[string]configuration.Workflow{})
-	_, _, err = digger.RunCommandsPerProject(commandsToRunPerProject, &depGraph, context.RepositoryOwner, context.Repository, eventName, prNumber, prManager, lock, reporter, planStorage, policyChecker, "")
-
-	_, _, err = digger.RunCommandsPerProject(commandsToRunPerProject, &depGraph, context.RepositoryOwner, context.Repository, eventName, prNumber, prManager, lock, reporter, planStorage, policyChecker, "")
-
+	_, _, err = digger.RunCommandsPerProject(commandsToRunPerProject, &depGraph, context.Repository, context.Repository, eventName, prNumber, prManager, lock, reporter, planStorage, policyChecker, "")
 	assert.NoError(t, err)
 	if err != nil {
 		fmt.Println(err)
diff --git a/pkg/policy/policy_test.go b/pkg/policy/policy_test.go
index 3079b275..fdc9b318 100644
--- a/pkg/policy/policy_test.go
+++ b/pkg/policy/policy_test.go
@@ -8,7 +8,7 @@ import (
 type OpaExamplePolicyProvider struct {
 }
 
-func (s *OpaExamplePolicyProvider) GetPolicy(_ string, _ string, _ string) (string, error) {
+func (s *OpaExamplePolicyProvider) GetPolicy(_ string, _ string) (string, error) {
 	return "package digger\n" +
 		"\n" +
 		"# user-role assignments\n" +
@@ -41,6 +41,10 @@ func (s *OpaExamplePolicyProvider) GetPolicy(_ string, _ string, _ string) (stri
 		"}", nil
 }
 
+func (s *OpaExamplePolicyProvider) GetOrganisation() string {
+	return "ORGANISATIONDIGGER"
+}
+
 type DiggerExamplePolicyProvider struct {
 }
 
@@ -60,6 +64,10 @@ func (s *DiggerExamplePolicyProvider) GetPolicy(_ string, _ string, _ string) (s
 		"", nil
 }
 
+func (s *DiggerExamplePolicyProvider) GetOrganisation() string {
+	return "ORGANISATIONDIGGER"
+}
+
 type DiggerExamplePolicyProvider2 struct {
 }
 
@@ -82,6 +90,10 @@ func (s *DiggerExamplePolicyProvider2) GetPolicy(_ string, _ string, _ string) (
 		"", nil
 }
 
+func (s *DiggerExamplePolicyProvider2) GetOrganisation() string {
+	return "ORGANISATIONDIGGER"
+}
+
 func TestDiggerPolicyChecker_Check(t *testing.T) {
 	type fields struct {
 		PolicyProvider PolicyProvider
@@ -145,9 +157,9 @@ func TestDiggerPolicyChecker_Check(t *testing.T) {
 		t.Run(tt.name, func(t *testing.T) {
 			var p = &DiggerPolicyChecker{
 				PolicyProvider: tt.fields.PolicyProvider,
-				ciService:      utils.MockPullRequestManager{Teams: []string{"engineering"}},
 			}
-			got, err := p.Check(tt.organisation, tt.name, tt.name, tt.command, tt.requestedBy)
+			ciService := utils.MockPullRequestManager{Teams: []string{"engineering"}}
+			got, err := p.Check(ciService, tt.organisation, tt.name, tt.name, tt.command, tt.requestedBy)
 			if (err != nil) != tt.wantErr {
 				t.Errorf("DiggerPolicyChecker.Check() error = %v, wantErr %v", err, tt.wantErr)
 				return