add edit example

This commit is contained in:
Gitea 2019-09-06 10:57:30 +01:00
parent 9ef8c746a7
commit 5002e79e29

31
src/edit.php Executable file
View File

@ -0,0 +1,31 @@
#!/usr/bin/php
<?php
/*******************************************************
* This will loop through all issues and add some custom
* text to the issue body. It will use a placeholder so
* that it can be automatically updated without replacing
* the whole issue body
********************************************************/
// load the config, create the connection and load the repo sepcified on the cmd line args
// we will then have $client and $repo available
require('setup.php');
//this is the function to generate the custom text
$text=function($issue){
return "\n```plain\n".$issue->number."\n".$issue->title."\ntexting\n".time()."\n```\n";
};
//callback function to add/replace the tag with our text
$tmp=function($issue) use ($text){
// add a tag to the body if to doesn't exist
if( strpos($issue->body,'<!--BOT-->')===false ){
$issue->body.='<hr/><!--BOT--><!--ENDBOT-->';
}
//replace the tag contents with the result from our $text function
$issue->body=preg_replace("#<!--BOT-->.*?<!--ENDBOT-->#s",'<!--BOT-->'.$text($issue).'<!--ENDBOT-->',$issue->body);
$issue->save();
};
//process ALL issues
$repo->forIssues($tmp);