Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Chessa
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
Síle Ekaterin Liszka
Chessa
Commits
6c47d6ea
Commit
6c47d6ea
authored
2 years ago
by
Síle Ekaterin Liszka
Browse files
Options
Downloads
Patches
Plain Diff
Chessa::Bug::GitHub: new plugin
parent
2ac09990
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/Chessa/Bug/GitHub.pm
+186
-0
186 additions, 0 deletions
scripts/Chessa/Bug/GitHub.pm
with
186 additions
and
0 deletions
scripts/Chessa/Bug/GitHub.pm
0 → 100644
+
186
−
0
View file @
6c47d6ea
package
Chessa::Bug::
GitHub
;
use
strict
;
use
warnings
;
use
feature
qw(:5.22)
;
use
Carp
qw(croak)
;
use
constant
{
name
=>
'
GitHub
',
};
use
JSON::
MaybeXS
;
use
DateTime::Format::
ISO8601
;
use
Syntax::Keyword::
Match
;
sub
new
{
my
$class
=
shift
;
my
$self
=
{};
my
(
$http
,
$log
,
$msg
,
$conf
)
=
@_
;
$self
->
{
log
}
=
$log
;
$self
->
{
msg
}
=
$msg
;
$self
->
{
conf
}
=
$conf
;
$self
->
{
irc
}
=
$self
->
{
conf
}{
irc
};
return
bless
$self
,
$class
||
ref
$class
;
}
sub
log
{
my
$self
=
shift
;
my
(
$msg
,
$on_info
,
$errors
)
=
@_
;
$self
->
{
log
}(
$msg
);
if
(
defined
(
$on_info
)
&&
$errors
)
{
$on_info
->
(
$msg
);
}
}
sub
error
{
my
$self
=
shift
;
my
(
$msg
,
$on_info
,
$errors
)
=
@_
;
$msg
=
$self
->
{
msg
}('
Error
',
$msg
);
$self
->
log
(
$msg
,
$on_info
,
$errors
);
}
sub
wants
{
my
$self
=
shift
;
my
(
$project
)
=
@_
;
if
(
$project
=~
m!^(gh|github):!i
)
{
return
1
;
}
return
0
;
}
sub
handle
{
my
$self
=
shift
;
my
(
$http
,
$on_info
,
$data
,
$errors
)
=
@_
;
my
(
$project
,
$num
,
$type
)
=
@
{
$data
};
$self
->
log
("
Got
$project
$type
$num
");
my
$base
=
"
https://api.github.com/repos/
$project
";
my
$func
;
if
(
!
exists
(
$self
->
{
projects
}{
$project
})
&&
(
$type
ne
'
snippets
'))
{
return
;
}
match
(
$type
:
eq
)
{
case
('
issues
')
{
$func
=
\
&issue
;
}
case
('
merge_requests
')
{
$type
=
'
pulls
';
$func
=
\
&mr
;
}
case
('
commits
')
{
$func
=
\
&commit
;
}
case
('
snippets
')
{
# absolutely no reason to bother with gists, lmfao
return
;
}
default
{
return
;
}
}
$base
.=
"
/
$type
/
$num
";
$self
->
log
("
Requesting
$base
");
$http
->
do_request
(
uri
=>
$base
,
headers
=>
{
'
Accept
'
=>
'
application/vnd.github.v3+json
',
},
on_response
=>
sub
{
my
(
$response
)
=
@_
;
$func
->
(
$self
,
$response
,
$on_info
,
$data
,
$errors
);
},
on_error
=>
sub
{
my
(
$msg
)
=
@_
;
$on_info
->
(
$self
->
{
msg
}('
Error
',
$msg
));
}
);
}
sub
issue
{
my
$self
=
shift
;
my
(
$response
,
$on_info
,
$data
,
$errors
)
=
@_
;
my
(
$project
,
$num
,
$type
)
=
@
{
$data
};
my
$json
=
JSON::
MaybeXS
->
new
->
utf8
->
decode
(
$response
->
decoded_content
);
my
%d
=
(
author
=>
'
@
'
.
$json
->
{
user
}{
login
},
title
=>
$json
->
{
title
},
id
=>
$num
,
url
=>
$json
->
{
html_url
},
state
=>
$json
->
{
state
},
);
my
$str
=
$self
->
{
msg
}("
$project
#
$d
{id}
",
$d
{
title
})
.
'
(
'
.
$self
->
{
msg
}('
Status
',
$d
{
state
})
.
'
'
.
$self
->
{
msg
}('
Author
',
$d
{
author
})
.
"
) -
$d
{url}
";
$on_info
->
(
$str
);
}
sub
mr
{
my
$self
=
shift
;
my
(
$response
,
$on_info
,
$data
,
$errors
)
=
@_
;
my
(
$project
,
$num
,
$type
)
=
@
{
$data
};
my
$json
=
JSON::
MaybeXS
->
new
->
utf8
->
decode
(
$response
->
decoded_content
);
my
%d
=
(
author
=>
'
@
'
.
$json
->
{
user
}{
login
},
title
=>
$json
->
{
title
},
id
=>
$num
,
url
=>
$json
->
{
html_url
},
state
=>
$json
->
{
state
},
target
=>
$json
->
{
base
}{
label
},
source
=>
$json
->
{
head
}{
label
},
labels
=>
[]
,
merge
=>
$json
->
{
mergeable_state
},
);
my
@labels
=
();
$d
{
merge
}
=~
s/_/ /g
;
if
(
exists
(
$json
->
{
labels
}))
{
for
my
$label
(
@
{
$json
->
{
labels
}})
{
push
@labels
,
$label
->
{
name
};
}
}
$d
{
labels
}
=
\
@labels
;
my
$str
=
$self
->
{
msg
}("
$project
!
$d
{id}
",
$d
{
title
})
.
'
(
'
.
$self
->
{
msg
}('
Status
',
$d
{
state
})
.
"
;
$d
{merge}
"
.
$self
->
{
msg
}('
Author
',
$d
{
author
})
.
'
)
'
.
$d
{
source
}
.
'
->
'
.
$d
{
target
};
if
(
@
{
$d
{
labels
}}
>
0
)
{
$str
.=
'
'
.
$self
->
{
msg
}('
Labels
',
join
('
',
@
{
$d
{
labels
}}));
}
$str
.=
"
-
$d
{url}
";
$on_info
->
(
$str
);
}
sub
commit
{
my
$self
=
shift
;
my
(
$response
,
$on_info
,
$data
,
$errors
)
=
@_
;
my
(
$project
,
$num
,
$type
)
=
@
{
$data
};
my
$json
=
JSON::
MaybeXS
->
new
->
utf8
->
decode
(
$response
->
decoded_content
);
my
%d
=
(
author
=>
$json
->
{
commit
}{
author
}{
name
}
.
'
<
'
.
$json
->
{
commit
}{
author
}{
email
}
.
'
>
',
commit
=>
$json
->
{
commit
}{
committer
}{
name
}
.
'
<
'
.
$json
->
{
commit
}{
committer
}{
email
}
.
'
>
',
title
=>
$json
->
{
commit
}{
message
},
id
=>
$num
,
url
=>
$json
->
{
html_url
},
);
my
$str
=
$self
->
{
msg
}("
$project
\@
$d
{id}
",
$d
{
title
})
.
'
(
'
.
$self
->
{
msg
}('
Author
',
$d
{
author
})
.
(
$d
{
author
}
ne
$d
{
commit
}
?
'
'
.
$self
->
{
msg
}('
Committer
',
$d
{
commit
})
:
'')
.
"
) -
$d
{url}
";
$on_info
->
(
$str
);
}
# A well-fed woof is a happy woof.
0xfeedbeef
;
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