Skip to content

Adding hooks during repository creation #2062

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

Closed
1 of 7 tasks
TomFreudenberg opened this issue Jun 26, 2017 · 13 comments
Closed
1 of 7 tasks

Adding hooks during repository creation #2062

TomFreudenberg opened this issue Jun 26, 2017 · 13 comments
Labels
type/feature Completely new functionality. Can only be merged if feature freeze is not active. type/proposal The new feature has not been accepted yet but needs to be discussed first.

Comments

@TomFreudenberg
Copy link

TomFreudenberg commented Jun 26, 2017

  • Gitea version (or commit ref): v1.1
  • Git version: 2.10.1 (Apple Git-78)
  • Operating system: OSX/Ubuntu
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

Hi, in case that your discourse forum currently is empty, I hopefully may ask this question here.

I currently use gitolite for a fine granulated rights management but like to replace it due to the nice interface from gitea and easier user experience.

It seems to me easy just to create some additional git-hooks to gitea which are working like gitolite.

Where is the "best place" to automatically integrate such kind of hooks. As I saw, the hooks from gitea, are prepared at models/repo.go->createDelegateHooks

https://github.com/go-gitea/gitea/blob/master/models/repo.go#L948-L981

Would this be the right place to also add some additional default hooks?

Thanks for a short hint how you would suggest to proceed.

Tom

@lunny
Copy link
Member

lunny commented Jun 26, 2017

You can add your hooks on the UI. on every repository's settings -> hooks

@lunny lunny added the type/question Issue needs no code to be fixed, only a description on how to fix it yourself. label Jun 26, 2017
@TomFreudenberg
Copy link
Author

Hi @lunny

thanks for your feedback.

Yes I know, that I can do this manually every time on a repository. I am looking for a solution to do this automatically every time a repo is newly created.

I would like to check also, if there could be an option to integrate within gitea, that maybe also the groups and rights for a user could be used for a granulated rights management.

So my question is: How to add additional hooks by default during gitea repo creation.

Thanks for help

@lafriks
Copy link
Member

lafriks commented Jun 26, 2017

You can change default hook templates system-wide in /usr/share/git-core/templates/hooks/

@TomFreudenberg
Copy link
Author

Hi @lafriks

ok, that is also an option but in case that they will only make sense to gitea integration and I also want them to be administrateable via the gitea gui, I think those should be added into gitea.

That is at least what I would prefer.

@TomFreudenberg
Copy link
Author

TomFreudenberg commented Jun 26, 2017

Content moved to #2090

@lunny
Copy link
Member

lunny commented Jun 27, 2017

maybe this PR will fix that? @TomFreudenberg #1975

@TomFreudenberg
Copy link
Author

TomFreudenberg commented Jun 27, 2017

Content moved to #2090

@lunny lunny added type/feature Completely new functionality. Can only be merged if feature freeze is not active. type/proposal The new feature has not been accepted yet but needs to be discussed first. and removed type/question Issue needs no code to be fixed, only a description on how to fix it yourself. labels Jun 28, 2017
@lunny lunny added this to the 1.x.x milestone Jun 28, 2017
@TomFreudenberg
Copy link
Author

Hi @lunny

should I do something else. If you marked that as feature and proposal, this means it can`t work currently? Correct?

Thanks for some guidiance.
Tom

@lafriks
Copy link
Member

lafriks commented Jun 29, 2017

It's marked as proposal for initial issue. Not having values in script arguments is other issue and is probably bug

@lafriks
Copy link
Member

lafriks commented Jun 29, 2017

Just checked and hooks seems to work just fine.
pre-receive:

#!/bin/sh

read oldrev newrev refname
echo "(pre-receive) Old revision: $oldrev"
echo "(pre-receive) New revision: $newrev"
echo "(pre-receive) Reference name: $refname"

update:

#!/bin/sh

refname="$1"
oldrev="$2"
newrev="$3"

echo "(update) Old revision: $oldrev"
echo "(update) New revision: $newrev"
echo "(update) Reference name: $refname"

post-receive:

#!/bin/sh

read oldrev newrev refname
echo "(post-receive) Old revision: $oldrev"
echo "(post-receive) New revision: $newrev"
echo "(post-receive) Reference name: $refname"

When pushing to repository I get output:

~/tmp/repo1$ git push
Username for 'http://localhost:3000': user1
Password for 'http://user1@localhost:3000': 
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 979 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: (pre-receive) Old revision: da71e16f337ac6b7beddaa7eada597b4c3357a9e
remote: (pre-receive) New revision: 0d3b36185327af7e7a6a4725f9bc2084143838d3
remote: (pre-receive) Reference name: refs/heads/master
remote: (update) Old revision: da71e16f337ac6b7beddaa7eada597b4c3357a9e
remote: (update) New revision: 0d3b36185327af7e7a6a4725f9bc2084143838d3
remote: (update) Reference name: refs/heads/master
remote: (post-receive) Old revision: da71e16f337ac6b7beddaa7eada597b4c3357a9e
remote: (post-receive) New revision: 0d3b36185327af7e7a6a4725f9bc2084143838d3
remote: (post-receive) Reference name: refs/heads/master
To http://localhost:3000/user1/repo1.git
   da71e16..0d3b361  master -> master

@lunny
Copy link
Member

lunny commented Jun 30, 2017

@TomFreudenberg I added this proposal and feature that you said

I am looking for a solution to do this automatically every time a repo is newly created.

This is a feature that Gitea didn't support. We need some PRs to do that, So I marked this as kind/feature and kind/proposal. Maybe you can try to do that?

Another issue you mentioned above is that custom hooks is not triggered when push, @lafriks has answered that.

Thanks,
Lunny

@TomFreudenberg
Copy link
Author

To do not overload this ticket, I have created a separate one and moved relevant content away. Hopefully you agree to that procedure.

@TomFreudenberg TomFreudenberg changed the title kind/question: Adding hooks during repository creation Adding hooks during repository creation Jun 30, 2017
@lunny lunny mentioned this issue Jul 6, 2019
4 tasks
@lunny lunny removed this from the 1.x.x milestone Nov 11, 2019
@lunny
Copy link
Member

lunny commented Nov 12, 2019

Replaced by #7365

@lunny lunny closed this as completed Nov 12, 2019
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/feature Completely new functionality. Can only be merged if feature freeze is not active. type/proposal The new feature has not been accepted yet but needs to be discussed first.
Projects
None yet
Development

No branches or pull requests

3 participants