grahamcampbell / laravel-gitlab Goto Github PK
View Code? Open in Web Editor NEWA GitLab API bridge for Laravel
Home Page: https://gjcampbell.co.uk
License: MIT License
A GitLab API bridge for Laravel
Home Page: https://gjcampbell.co.uk
License: MIT License
We recently crossed the threshold of 100 projects, which is the maximum amount of items the GitLab API will return at once. In order to fetch all results, I have discovered that the base PHP GitLab API library exposes a mechanism to page over all results: https://github.com/GitLabPHP/Client#example-with-pager
How can this be used with this package? My guess is that I would have to get the underlying client instance like this:
/** @var \GrahamCampbell\GitLab\GitLabManager $gitLabManager */
$pager = new \GitLab\ResultPager($gitLabManager->connection());
I propose that we either:
pager(): \GitLab\ResultPager
to \GrahamCampbell\GitLab\GitLabManager
Open for better suggestions, of course.
Hello,
i've try delete user either from projects or from group. but always get 404 not found.
$project = Gitlab::Projects()->show($projectId);
$projectPermissions = $project['permissions'];
$groupId = $project['namespace']['parent_id'];
if ( empty($projectPermissions['project_access']) && !empty($projectPermissions['group_access'])) {
// delete from group member
try {
Gitlab::Groups()->removeMember($groupId, $userId);
$removed[] = "remove user id : " . $userId . " from group id : " . $projectId;
} catch(\Exception $e) {
$removed[] = $e->getMessage();
}
} else if ( empty($projectPermissions['group_access']) && !empty($projectPermissions['project_access'])) {
//delete from project member
try {
Gitlab::Projects()->removeMember($projectId, $userId);
$removed[] = "remove user id : " . $userId . " from project id : " . $projectId;
} catch(\Exception $e) {
$removed[] = $e->getMessage();
}
}
is it permission problem?, then i found the second problem.
i've been read the docs, but i don't now how to set oauth dynamic by user or is it possible, or maybe i have wrong logic in my mind?
i have a case user login via oauth token, and use the token from logged in user oauth token for accessing gitlab repo.
so by those token we can use it as for managing repo.
my problem is every user login and the app still use my user as a basis. so even the project owner or group owner can't delete member. the error says 404.
i've been set the connection in config/gitlab.php
'connections' => [
'main' => [
'token' => i set this with my private token',
'method' => 'token',
],
'alternative' => [
'token' => 'your-token', <- how to set this dynamically by logged in user after redirect callback
'method' => 'oauth',
],
],
how to set oauth token dynamically?
if been try
$client = Gitlab::authenticate($getInfo->token, 'oauth_token');
still not work.
thank you for your answer.
Description
According to gitlab docs it's possible to list merge requests of given group.
Example
$this->gitLab->groups()->mergeRequests($group['id'])->all()
Hi @GrahamCampbell – thanks for the project.
$projects = GitLab::projects()->all();
For this request I get is an array with 20 elements only – is it limited? It should be clearly more than that.
Same groups
, Issues
, mergeRequests
, namespaces
and users
Am I missing something?
Thank you.
I updated the package from 3.3
to 4.0
and I get the error:
Cannot unpack array with string keys
at C:\dev\domains\tunnel\vendor\m4tthumphrey\php-gitlab-api\src\ResultPager.php:81
77▕ * @return array
78▕ */
79▕ public function fetch(ApiInterface $api, string $method, array $parameters = [])
80▕ {
➜ 81▕ $result = $api->perPage($this->perPage)->$method(...$parameters);
82▕
83▕ if (!\is_array($result)) {
84▕ throw new RuntimeException('Pagination of this endpoint is not supported.');
85▕ }
1 C:\dev\domains\tunnel\vendor\m4tthumphrey\php-gitlab-api\src\ResultPager.php:122
Gitlab\ResultPager::fetch(Object(Gitlab\Api\Projects), "hooks", [])
2 [internal]:0
Gitlab\ResultPager::fetchAllLazy(Object(Gitlab\Api\Projects), "hooks", [])
package | in composer | installed version |
---|---|---|
php | ^7.3 |
7.4.12 |
composer | --- | 2.0.6 |
graham-campbell/gitlab | ^4.0 |
4.0.0 |
m4tthumphrey/php-gitlab-api | --- | 10.0.2 |
"require": {
"php": "^7.3",
"fideloper/proxy": "^4.3",
"fruitcake/laravel-cors": "^2.0",
"graham-campbell/gitlab": "^4.0",
"guzzlehttp/guzzle": "^7.0",
"laravel/framework": "^8.7",
"laravel/slack-notification-channel": "^2.2",
"http-interop/http-factory-guzzle": "^1.0"
},
There are no such problems in version 3.3 of graham-campbell/gitlab
.
I saw this was discussed previously in #16. It is true that webhook usage is not hard, although this library could make it easier by adding a clear path on how it can be implemented.
The controller method you suggested in #16 (comment) seems like a great idea. Are you open to adding that into the library, together with a bit of documentation around how to use it?
Ideas for further improvement:
I would be willing to provide a PR.
Would be nice, to keep up with new versions
Hello, I'm trying to execute actions after a fork is completed, but can't find a way of waiting for the call to complete.
I want to do this:
$fork = GitLab::projects()->fork($original['id'], [
'namespace' => trim($destino, '/'),
'name' => $nombre,
'path' => Str::slug($ruta)
]);
// Desconectarlo del repositorio original
GitLab::projects()->removeForkRelation($fork['id']);
Is there any way of doing this?
Thank you in advance for your help.
Hi there,
When can we expect this package updated for Laravel 11?
Should the token be of one of the admin?
Can you explain more about the other options available , OAuth flow?
How do I create an issue with this package?
I can retrieve the correct project as an array, but it shows as an array, rather than \Gitlab\Models\Project
. so I can't call the createIssue
method.
I retrieved the project like this. because there wasn't a "find by id" either. at least not from what I could see in the documentation.
collect($this->manager->projects()->all())->firstWhere('id', $projectId)
Thanks
Guzzle, and thereby curl do not like SSL domains being accessed that aren't known Certificate Authorities.
In the past I could do this:
$options = [
'verify' => '/var/www/laravel/storage/certs/UserTrust.pem',
];
$client = new \GuzzleHttp\Client();
$client->get('https://randomssldomain.com', $options);
How could I add the 'verify' flag to the underlying Guzzle6 adapter configuration to use your library?
Could you please update m4tthumphrey/php-gitlab-api requirement to version 9.13.0?
Thanks!
Are gitlab webhooks supported by the library?
If not are there any plans to add support in future?
in the gitlab Api we can get a merge request's pipelines (in order to know the MR's build status for example)
Something like this in "MergeRequests.php":
` /**
* @param int $project_id
* @param int $mr_id
* @return mixed
*/
public function pipelines($project_id, $mr_id)
{
return $this->get($this->getProjectPath($project_id, 'merge_requests/'.
$this->encodePath($mr_id).'/pipelines'));
}
`
Hi, I apologise if this is a dumb question!
I call am using this code
<?php
namespace App\Http\Controllers\API\Integrations\GitLab;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use GrahamCampbell\GitLab\Facades\GitLab;
use GrahamCampbell\GitLab\GitLabManager;
class GitLabsController extends Controller
{
function __construct() {
}
public function index(){
$projects = GitLab::Projects();
return response()->json($projects);
}
}
in my controller (I have put my access token in the config settings)
but its returning an empty array,
Can you advise what I am doing wrong?
Support for the version 11.10 is needed so we can have access to http-message 2.0
I was looking through the code but can't see if there is a way to mix the classes, if not we might be able to provide a PR with the missing function in Groups.php class.
Basically this is currently missing https://docs.gitlab.com/ee/api/merge_requests.html#list-group-merge-requests
Which is essentially a mix of the Groups.php and MergeRequests.php?
Hello,
I am creating a project that users can add their tokens to read their projects to distribute packages like packagist does but for gitlab CI/CD.
But I don't see how I can do it since I only see that to add the token, you have to add it in config/gitlab.php
'main' => [
'token' => 'your-token',
'method' => 'token',
]
Is there a way to customize the token and domain by code?
Thank you.
Hi guys.
I have an issue with ResultPager, My code goes like this:
$client = new Client();
$pager = new ResultPager($client,20);
$issues = $pager->fetchAll($client->repositories(), 'commits', [11261183]);
and get back with the response array of all 700 commits not paged :(
Am I doing something wrong? Please help with this issue. Pagination is a must in my implementation of API.
We've recently switched to this package for working with the Gitlab API. But it seems that this package is not really designed to use with a self hosted Gitlab instance? There is no configuration where we can specify our Gitlab URL. Only thing we can do is use the ->setUrl()
method everytime, this doesn't really seem like a nice solution.
Am I missing some configuration step?
Description
See https://docs.gitlab.com/ee/api/users.html#for-admins
For example sort:
The option "sort" does not exist.
Hi firstly thanks for dealing with my last issue so rapidly. Sadly after successfully installing the package and registering the service provider and alias as well as creating and configuring the git-lab config file I am now getting the following error.
I have gone down the rabbit hole for a while and I think its losing the config at some point. Or that i have done some sort of rookie mistake :) .
Hi i have recently tried to install your package, however a new dependency on Laravel called Nexmo seems to be conflicting with your composer require. Any help would be appreciated.
My apologies if I've missed this functionality, but I don't see how to make the all()
methods return paged results from the GitLab API. The php-gitlab-api project provides a ResultPager class which fetches all pages, but that does not appear to be used.
For example, this fetches only the first page of my projects:
$projectData = $this->gitLabManager->projects()->all();
I can explicitly use a pager to get all:
$client = $this->gitLabManager->connection();
$pager = new \Gitlab\ResultPager($client);
$projectData = $pager->fetchAll($client->api('projects'),'all');
Is there a way to have the all()
method do the same?
To avoid change repo urls, could an organization be made for this repo and put there?
Hi @GrahamCampbell, thanks for releasing https://github.com/GitLabPHP/Client/releases/tag/11.8.0
It would be nice to have a version of this library that allows it. Given that the project adheres to Semantic Versioning, the constraint could be loosened to ^11.6
: https://github.com/GitLabPHP/Client/blob/38380c933ada8fd2099bc611f0de23c339cdb04a/CHANGELOG.md?plain=1#L6
I have the following routes as oauth callback and redirect.
Route::get('/oauth', function () {
return Socialite::driver('gitlab')->redirect();
});
Route::get('/redirect', function () {
$user = Socialite::driver('gitlab')->user();
var_dump($user->token);
return redirect('/')->withCookie(cookie('token', $user->token, 15));
});
Route::get('/', function () {
$projects = GitLab::Projects()->all();
dd($projects);
});
I can check the token and verify that an oauth token is being provided after login, but then, I get a 401 unauthorized when I make the projects call.
gitlab.php config is as follows:
'main' => [
'token' => $_COOKIE['token'],
'method' => 'oauth',
// 'backoff' => false,
// 'cache' => false,
// 'sudo' => null,
'url' => 'http://git.org.com/api/v4/',
],
PHP version: 7.4.3 (hint: php --version
)
Description
According to: gitlab docs merge requests are can be filtered by reviewer_id && reviewer_username. Options resolver does not know those attributes.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.