Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Trac2Gitlab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stud.IP
Plugins
Trac2Gitlab
Commits
a3228846
Commit
a3228846
authored
3 years ago
by
Jan-Hendrik Willms
Browse files
Options
Downloads
Patches
Plain Diff
fixes
#20
parent
bb253b68
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
controllers/issues.php
+20
-21
20 additions, 21 deletions
controllers/issues.php
controllers/users.php
+29
-0
29 additions, 0 deletions
controllers/users.php
lib/EventController.php
+53
-0
53 additions, 0 deletions
lib/EventController.php
plugin.manifest
+1
-1
1 addition, 1 deletion
plugin.manifest
with
103 additions
and
22 deletions
controllers/issues.php
+
20
−
21
View file @
a3228846
<?php
<?php
/**
final
class
IssuesController
extends
TracToGitlab\EventController
* @property Parsedown $parsedown
*/
final
class
IssuesController
extends
\TracToGitlab\Controller
{
{
const
SECRET_ISSUE_OPEN
=
'N]<d5V/6tn/sYNMy'
;
const
SECRET_ISSUE_OPEN
=
'N]<d5V/6tn/sYNMy'
;
...
@@ -17,35 +14,36 @@ final class IssuesController extends \TracToGitlab\Controller
...
@@ -17,35 +14,36 @@ final class IssuesController extends \TracToGitlab\Controller
throw
new
MethodNotAllowedException
();
throw
new
MethodNotAllowedException
();
}
}
if
(
$_SERVER
[
'HTTP_X_GITLAB_TOKEN'
]
!==
self
::
SECRET_ISSUE_OPEN
)
{
if
(
!
$this
->
verifySecret
(
self
::
SECRET_ISSUE_OPEN
)
)
{
throw
new
AccessDeniedException
();
throw
new
AccessDeniedException
();
}
}
$input
=
file_get_contents
(
'php://input'
);
if
(
$this
->
getFromPayload
(
'object_attributes'
,
'action'
)
===
'open'
)
{
$payload
=
json_decode
(
$input
,
true
);
$username
=
$this
->
getFromPayload
(
'user'
,
'username'
);
$email
=
$this
->
getFromPayload
(
'user'
,
'email'
);
if
(
$payload
[
'object_attributes'
][
'action'
]
===
'open'
)
{
$user
=
User
::
findOneByUsername
(
$username
)
$user
=
User
::
findOneByUsername
(
$payload
[
'user'
][
'username'
])
??
User
::
findOneByEmail
(
$email
)
??
User
::
findOneByEmail
(
$payload
[
'user'
][
'email'
])
??
User
::
findOneByUsername
(
'gitlab-bot'
);
??
User
::
findOneByUsername
(
'gitlab-bot'
);
if
(
$user
)
{
if
(
$user
)
{
$labels
=
$this
->
getFromPayload
(
'labels'
);
foreach
(
self
::
LABEL_MAPPING
as
$label
=>
$definition
)
{
foreach
(
self
::
LABEL_MAPPING
as
$label
=>
$definition
)
{
if
(
!
$this
->
hasLabel
(
$
payload
,
$label
))
{
if
(
!
$this
->
hasLabel
(
$
labels
,
$label
))
{
continue
;
continue
;
}
}
$title
=
sprintf
(
$title
=
sprintf
(
$definition
[
2
],
$definition
[
2
],
$
p
ayload
[
'object_attributes'
][
'iid'
]
,
$
this
->
getFromP
ayload
(
'object_attributes'
,
'iid'
)
,
$
p
ayload
[
'object_attributes'
][
'title'
]
$
this
->
getFromP
ayload
(
'object_attributes'
,
'title'
)
);
);
$body
=
Studip\Markup
::
markAsHtml
(
$body
=
Studip\Markup
::
markAsHtml
(
$this
->
parsedown
->
text
(
$this
->
parsedown
->
text
(
sprintf
(
sprintf
(
"%s
\n\n
----
\n
Zum [gitlab-Issue #%u](%s)"
,
"%s
\n\n
----
\n
Zum [gitlab-Issue #%u](%s)"
,
trim
(
$p
ayload
[
'object_attributes'
][
'description'
]
),
$this
->
getFromP
ayload
(
'object_attributes'
,
'description'
),
$
p
ayload
[
'object_attributes'
][
'iid'
]
,
$
this
->
getFromP
ayload
(
'object_attributes'
,
'iid'
)
,
$
p
ayload
[
'object_attributes'
][
'url'
]
$
this
->
getFromP
ayload
(
'object_attributes'
,
'url'
)
)
)
)
)
);
);
...
@@ -59,18 +57,19 @@ final class IssuesController extends \TracToGitlab\Controller
...
@@ -59,18 +57,19 @@ final class IssuesController extends \TracToGitlab\Controller
);
);
$this
->
gitlab
->
issues
()
->
addNote
(
$this
->
gitlab
->
issues
()
->
addNote
(
$
p
ayload
[
'project'
][
'id'
]
,
$
this
->
getFromP
ayload
(
'project'
,
'id'
)
,
$
p
ayload
[
'object_attributes'
][
'iid'
]
,
$
this
->
getFromP
ayload
(
'object_attributes'
,
'iid'
)
,
"[Zum Forenbeitrag auf dem Entwicklungsserver](
{
$url
}
)"
"[Zum Forenbeitrag auf dem Entwicklungsserver](
{
$url
}
)"
);
}
);
}
}
}
}
}
$this
->
render_nothing
();
$this
->
render_nothing
();
}
}
private
function
hasLabel
(
array
$
change
,
string
$needle
):
bool
private
function
hasLabel
(
array
$
labels
,
string
$needle
):
bool
{
{
foreach
(
$
change
[
'
labels
'
]
as
$label
)
{
foreach
(
$labels
as
$label
)
{
if
(
$label
[
'title'
]
===
$needle
)
{
if
(
$label
[
'title'
]
===
$needle
)
{
return
true
;
return
true
;
}
}
...
...
This diff is collapsed.
Click to expand it.
controllers/users.php
0 → 100644
+
29
−
0
View file @
a3228846
<?php
final
class
UsersController
extends
TracToGitlab\EventController
{
const
SECRET_USER_CREATED
=
'q<-%Y7Ys>h(@LHgg'
;
public
function
created_action
()
{
if
(
!
Request
::
isPost
())
{
throw
new
MethodNotAllowedException
();
}
if
(
!
$this
->
verifySecret
(
self
::
SECRET_USER_CREATED
)
||
!
$this
->
verifyEventType
(
'System Hook'
)
)
{
throw
new
AccessDeniedException
();
}
if
(
$this
->
getFromPayload
(
'event_name'
)
===
'user_create'
)
{
$this
->
gitlab
->
projects
()
->
addMember
(
$this
->
gitlabProjectId
,
$this
->
getFromPayload
(
'user_id'
),
10
);
}
$this
->
render_nothing
();
}
}
This diff is collapsed.
Click to expand it.
lib/EventController.php
0 → 100644
+
53
−
0
View file @
a3228846
<?php
namespace
TracToGitlab
;
abstract
class
EventController
extends
Controller
{
private
$payload
=
null
;
protected
function
verifySecret
(
string
$secret
):
bool
{
return
$_SERVER
[
'HTTP_X_GITLAB_TOKEN'
]
===
$secret
;
}
protected
function
verifyEventType
(
string
$type
):
bool
{
return
$_SERVER
[
'HTTP_X_GITLAB_EVENT'
]
===
$type
;
}
protected
function
getFromPayload
(...
$keys
)
{
if
(
$this
->
payload
===
null
)
{
$this
->
payload
=
$this
->
getPayloadFromRequest
()
??
false
;
}
if
(
$this
->
payload
===
false
)
{
throw
new
\Exception
(
'No payload detected'
);
}
$result
=
$this
->
payload
;
foreach
(
$keys
as
$key
)
{
if
(
!
isset
(
$result
[
$key
]))
{
throw
new
\Exception
(
"Invalid payload key
{
$key
}
"
);
}
$result
=
$result
[
$key
];
}
return
$result
;
}
private
function
getPayloadFromRequest
():
?array
{
$input
=
file_get_contents
(
'php://input'
);
if
(
!
$input
)
{
return
null
;
}
$payload
=
json_decode
(
$input
,
true
);
if
(
!
$payload
||
!
is_array
(
$payload
))
{
return
null
;
}
return
$payload
;
}
}
This diff is collapsed.
Click to expand it.
plugin.manifest
+
1
−
1
View file @
a3228846
pluginname=Trac to gitlab converter
pluginname=Trac to gitlab converter
pluginclassname=TracToGitlabPlugin
pluginclassname=TracToGitlabPlugin
origin=UOL
origin=UOL
version=1.1
version=1.1
.1
studipMinVersion=5.0
studipMinVersion=5.0
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment