codemonth.dk

One project every month - making stuff better ...

GITHUB_UTL Tutorial 4: Creating issues and updating them.

In this tutorial I will take a look at how to create issues against existing projects. This is a nice feature of GitHub since it lets us track issues directly where we have the code located. The first thing we will do is create a new issue.

As always my parameters for this session is:
ParameterValue
Wallet location/home/oracle/wallet
Wallet passwordWalletPasswd123
GitHub.com usernamegithub-user
GitHub.com passwordgitPass123

To create a new issue we simply use the procedure create_issue in the main github_issues package:

begin

-- Set wallet parameters for the session
github.set_session_wallet('file:/home/oracle/wallet', 'WalletPasswd123');

-- Set github account for session
github.set_logon_info('github-user', 'gitPass123');

-- Create an issue for our github_utl repository
github_issues.create_issue(
git_account => 'github-user'
, repos_name => 'github_utl_test'
, title => 'No attribution in file'
, body => 'We need to write who created the pacakge in the Hello.txt file'
, assignee => 'github-user'
);

end;
/

After you run that block of code, go to your github repository page, and click the issues tab on the right side. There you should see the newly created issue, and it should be assigned to you. Click on the issue and note the number, that has been assigned to it. If you have not created any other issues in this repository it should have an ID of 1. In a later tutorial I will show you how to extract those IDs from within oracle as well.

Next we will add a comment, saying that we know how to fix this issue and when it is done, we can close the issue. For this we will use the id of the new issue to associate the comment to that specific issue.

begin

-- Set wallet parameters for the session
github.set_session_wallet('file:/home/oracle/wallet', 'WalletPasswd123');

-- Set github account for session
github.set_logon_info('github-user', 'gitPass123');

-- Create a comment for the new issue
github_issues_comments.create_comment(
git_account => 'github-user'
, repos_name => 'github_utl_test'
, issue_id => 1
, body => 'Dont worry, I know just how to fix this'
);

end;
/

Again, go to your issue list for the repository on github.com and verify that the new comment has been added below the issue itself.

So now let us go fix that problem and close the issue once it has been resolved. First let us make sure we have the latest SHA of the file, for updating it, using the code from tutorial 3:

set serveroutput on;
declare
myjson github.call_result;
begin

-- Set wallet parameters for the session
github.set_session_wallet('file:/home/oracle/wallet', 'WalletPasswd123');

-- Set github account for session
github.set_logon_info('github-user', 'gitPass123');
myjson := github_repos_content.get_content(
git_account => 'github-user'
, repos_name => 'github_utl_test'
, path => 'Hello.txt'
);

-- With the response json we ask for the SHA. If not set, file does not exists
dbms_output.put_line('SHA of existing file: ' || json_ext.get_string(myjson, 'sha'));

end;
/

Now that we have the new SHA, we can update the file:

begin

-- Set wallet parameters for the session
github.set_session_wallet('file:/home/oracle/wallet', 'WalletPasswd123');

-- Set github account for session
github.set_logon_info('github-user', 'gitPass123');

-- Update the contents of our file using the SHA from the previous call
github_repos_content.update_file (
git_account => 'github-user'
, repos_name => 'github_utl_test'
, path => 'Hello.txt'
, message => 'We are updating the file'
, content => github.encode64_clob('GITHUB_UTL is an awesome package! Written by: Morten Egan http://www.github.com/github-user')
, sha => 'fcd09c537718a1cb9d04a1d5b3754c9e093ff907'
);

end;
/

After the file has been updated, let us update the issue and close it:

begin

-- Set wallet parameters for the session
github.set_session_wallet('file:/home/oracle/wallet', 'WalletPasswd123');

-- Set github account for session
github.set_logon_info('github-user', 'gitPass123');

-- Add fixed comment
github_issues_comments.create_comment(
git_account => 'github-user'
, repos_name => 'github_utl_test'
, issue_id => 1
, body => 'Fixed'
);

-- Update an issue for our github_utl repository
github_issues.edit_issue(
git_account => 'github-user'
, repos_name => 'github_utl_test'
, issue_number => 1
, title => 'No attribution in file'
, state => 'closed'
);

end;
/

So now you know to create issues, comments and update existing issues. The next tutorial will show how you handle the different response doucments from the services that we have used so far. For instance, how can you see the sha's of the different objects in your repository? How can you list all your repositories? How can you see all the issues and how do join this data locally?

Tagged in : Advanced Queuing, DBMS_NETWORK_ACL_ADMIN, DBMS_SCHEDULER, Database Triggers, UTL_ENCODE, UTL_HTTP, UTL_RAW, sys_context