@@ -17,19 +17,59 @@ public static function getLatestResolvableVersion(array $args): ?string
1717 [$ workingDirectory , $ dependencyName , $ gitCredentials , $ registryCredentials ] = $ args ;
1818
1919 $ httpBasicCredentials = [];
20+ $ bearerCredentials = [];
21+ $ githubOauthCredentials = [];
22+ $ gitlabOauthCredentials = [];
23+ $ gitlabTokenCredentials = [];
24+ $ bitbucketOauthCredentials = [];
2025
2126 foreach ($ gitCredentials as $ credentials ) {
22- $ httpBasicCredentials [$ credentials ['host ' ]] = [
23- 'username ' => $ credentials ['username ' ],
24- 'password ' => $ credentials ['password ' ],
25- ];
27+ if (isset ($ credentials ['host ' ]) && isset ($ credentials ['username ' ]) && isset ($ credentials ['password ' ])) {
28+ $ httpBasicCredentials [$ credentials ['host ' ]] = [
29+ 'username ' => $ credentials ['username ' ],
30+ 'password ' => $ credentials ['password ' ],
31+ ];
32+ }
2633 }
2734
2835 foreach ($ registryCredentials as $ credentials ) {
29- $ httpBasicCredentials [$ credentials ['registry ' ]] = [
30- 'username ' => $ credentials ['username ' ],
31- 'password ' => $ credentials ['password ' ],
32- ];
36+ $ host = $ credentials ['registry ' ] ?? null ;
37+ if (!$ host ) {
38+ continue ;
39+ }
40+
41+ // http-basic
42+ if (isset ($ credentials ['username ' ]) && isset ($ credentials ['password ' ])) {
43+ $ httpBasicCredentials [$ host ] = [
44+ 'username ' => $ credentials ['username ' ],
45+ 'password ' => $ credentials ['password ' ],
46+ ];
47+ }
48+
49+ $ authType = $ credentials ['auth_type ' ] ?? null ;
50+ // bearer
51+ if ($ authType === 'bearer ' && isset ($ credentials ['token ' ])) {
52+ $ bearerCredentials [$ host ] = $ credentials ['token ' ];
53+ }
54+ // github-oauth
55+ if ($ authType === 'github-oauth ' && isset ($ credentials ['token ' ])) {
56+ $ githubOauthCredentials [$ host ] = $ credentials ['token ' ];
57+ }
58+ // gitlab-oauth
59+ if ($ authType === 'gitlab-oauth ' && isset ($ credentials ['token ' ])) {
60+ $ gitlabOauthCredentials [$ host ] = $ credentials ['token ' ];
61+ }
62+ // gitlab-token
63+ if ($ authType === 'gitlab-token ' && isset ($ credentials ['token ' ])) {
64+ $ gitlabTokenCredentials [$ host ] = $ credentials ['token ' ];
65+ }
66+ // bitbucket-oauth
67+ if ($ authType === 'bitbucket-oauth ' && (isset ($ credentials ['key ' ]) || isset ($ credentials ['consumer-key ' ]) || isset ($ credentials ['username ' ])) && (isset ($ credentials ['secret ' ]) || isset ($ credentials ['consumer-secret ' ]) || isset ($ credentials ['password ' ]))) {
68+ $ bitbucketOauthCredentials [$ host ] = [
69+ 'consumer-key ' => $ credentials ['key ' ] ?? $ credentials ['consumer-key ' ] ?? $ credentials ['username ' ] ?? '' ,
70+ 'consumer-secret ' => $ credentials ['secret ' ] ?? $ credentials ['consumer-secret ' ] ?? $ credentials ['password ' ] ?? '' ,
71+ ];
72+ }
3373 }
3474
3575 $ io = new ExceptionIO ();
@@ -38,13 +78,28 @@ public static function getLatestResolvableVersion(array $args): ?string
3878
3979 $ config = $ composer ->getConfig ();
4080
41- if (0 < count ($ httpBasicCredentials )) {
42- $ config ->merge ([
43- 'config ' => [
44- 'http-basic ' => $ httpBasicCredentials ,
45- ],
46- ]);
81+ $ configToMerge = ['config ' => []];
82+ if (!empty ($ httpBasicCredentials )) {
83+ $ configToMerge ['config ' ]['http-basic ' ] = $ httpBasicCredentials ;
84+ }
85+ if (!empty ($ bearerCredentials )) {
86+ $ configToMerge ['config ' ]['bearer ' ] = $ bearerCredentials ;
87+ }
88+ if (!empty ($ githubOauthCredentials )) {
89+ $ configToMerge ['config ' ]['github-oauth ' ] = $ githubOauthCredentials ;
90+ }
91+ if (!empty ($ gitlabOauthCredentials )) {
92+ $ configToMerge ['config ' ]['gitlab-oauth ' ] = $ gitlabOauthCredentials ;
93+ }
94+ if (!empty ($ gitlabTokenCredentials )) {
95+ $ configToMerge ['config ' ]['gitlab-token ' ] = $ gitlabTokenCredentials ;
96+ }
97+ if (!empty ($ bitbucketOauthCredentials )) {
98+ $ configToMerge ['config ' ]['bitbucket-oauth ' ] = $ bitbucketOauthCredentials ;
99+ }
47100
101+ if (!empty ($ configToMerge ['config ' ])) {
102+ $ config ->merge ($ configToMerge );
48103 $ io ->loadConfiguration ($ config );
49104 }
50105
0 commit comments