Topic
  • 5 replies
  • Latest Post - ‏2008-05-07T21:13:06Z by sgw
SystemAdmin
SystemAdmin
24948 Posts

Pinned topic External Script to Submit CR using API

‏2008-05-01T18:43:33Z |
Hello
Does anyone have a sample script they can share that will submit a defect from outside of CQ? I have been looking over the API and trying to figure out how to do this without luck.
Any input would be greatly appreciated.
Marlene B
Updated on 2008-05-07T21:13:06Z at 2008-05-07T21:13:06Z by sgw
  • sgw
    sgw
    1003 Posts

    Re: External Script to Submit CR using API

    ‏2008-05-02T04:19:03Z  
    Marlene,
    Here is a simple Perl version.
    -Sean
  • SystemAdmin
    SystemAdmin
    24948 Posts

    RE: [clearquest] External Script to Submit CR using API

    ‏2008-05-02T15:35:53Z  

    Does anyone have a sample script they can share that will
    submit a defect from outside of CQ? I have been looking over
    the API and trying to figure out how to do this without luck.

    Any input would be greatly appreciated.

    I guess now is as good a time as any to introduce my lovely Python ClearQuest modules!

    O:\>python
    ActivePython 2.5.1.1 (ActiveState Software Inc.) based on
    Python 2.5.1 (r251:54863, May 1 2007, 17:47:05) http://MSC v.1310 32 bit (Intel) on win32
    Type "help", "copyright", "credits" or "license" for more information.
    from clearquest import api
    session = api.Session()
    session.UserLogon('admin', '', 'SAMPL', api.SessionType.Shared, 'Sample')
    bug = session.create('Defect')
    bug.Headline = 'Foobar'
    bug.Description = 'This is a new bug.'
    bug.Severity = '2-Major'
    bug.Owner = 'QE'
    bug.save()

    And wallah, you have a new defect! Lets look at the Perl equivalent:

    use strict;
    use warnings;
    use CQPerlExt;

    my $session = CQSession::Build();
    $session->UserLogon('admin', '', 'SAMPL', 'Sample');
    $entity = $session->BuildEntity('Defect');
    $entity->SetFieldValue('Headline', 'Foobar');
    $entity->SetFieldValue('Description', 'This is a new bug.');
    $entity->SetFieldValue('Severity', '2-Major');
    $entity->SetFieldValue('Owner', 'QE');
    my $error = $entity->Validate();
    if ($error) {
    print "Error occurred: $error\n";
    } else {
    $entity->Commit();
    }

    Oh my. I know which approach I'd prefer.

    I've actually open sourced these Python/ClearQuest modules -- they're living at http://code.google.com/p/cqpython/. In true developer form there's absolutely zero documentation as to how you'd get started with them. So here's a quick guide:

    1. Install ActiveState Python 2.5.
    2. Install IPython, an enhanced interactive Python console. I use this exclusively these days. You can get tab-completion on objects. In the example above, if I had typed 'bug.', then pressed tab, I'd get a list of all the fields I'd be able to set. You can get IPython from here: http://ipython.scipy.org/dist/ipython-0.8.2.win32-setup.exe
    3. Install Subversion. http://subversion.tigris.org/files/documents/15/41686/svn-1.4.6-setup.exe
    4. Open up a command prompt (Start->Run->cmd). cd to C:\Python25\Lib\site-packages.
    5. Check out the ClearQuest Python library:
    C:\Python25\Lib\site-packages>svn co http://cqpython.googlecode.com/svn/branches/0.9.x/src/clearquest

    Then you can start Python, import the module via 'from clearquest import api', and repeat the same steps above!

    Enjoy!

    Trent.

    --
    http://www.onresolve.com

    _______________________________________________
    clearquest mailing list
    clearquest@lists.ca.ibm.com
    Unsubscribe:clearquest-leave@lists.ca.ibm.com
  • sgw
    sgw
    1003 Posts

    Re: RE: [clearquest] External Script to Submit CR using API

    ‏2008-05-02T18:07:21Z  

    Does anyone have a sample script they can share that will
    submit a defect from outside of CQ? I have been looking over
    the API and trying to figure out how to do this without luck.

    Any input would be greatly appreciated.

    I guess now is as good a time as any to introduce my lovely Python ClearQuest modules!

    O:\>python
    ActivePython 2.5.1.1 (ActiveState Software Inc.) based on
    Python 2.5.1 (r251:54863, May 1 2007, 17:47:05) http://MSC v.1310 32 bit (Intel) on win32
    Type "help", "copyright", "credits" or "license" for more information.
    from clearquest import api
    session = api.Session()
    session.UserLogon('admin', '', 'SAMPL', api.SessionType.Shared, 'Sample')
    bug = session.create('Defect')
    bug.Headline = 'Foobar'
    bug.Description = 'This is a new bug.'
    bug.Severity = '2-Major'
    bug.Owner = 'QE'
    bug.save()

    And wallah, you have a new defect! Lets look at the Perl equivalent:

    use strict;
    use warnings;
    use CQPerlExt;

    my $session = CQSession::Build();
    $session->UserLogon('admin', '', 'SAMPL', 'Sample');
    $entity = $session->BuildEntity('Defect');
    $entity->SetFieldValue('Headline', 'Foobar');
    $entity->SetFieldValue('Description', 'This is a new bug.');
    $entity->SetFieldValue('Severity', '2-Major');
    $entity->SetFieldValue('Owner', 'QE');
    my $error = $entity->Validate();
    if ($error) {
    print "Error occurred: $error\n";
    } else {
    $entity->Commit();
    }

    Oh my. I know which approach I'd prefer.

    I've actually open sourced these Python/ClearQuest modules -- they're living at http://code.google.com/p/cqpython/. In true developer form there's absolutely zero documentation as to how you'd get started with them. So here's a quick guide:

    1. Install ActiveState Python 2.5.
    2. Install IPython, an enhanced interactive Python console. I use this exclusively these days. You can get tab-completion on objects. In the example above, if I had typed 'bug.', then pressed tab, I'd get a list of all the fields I'd be able to set. You can get IPython from here: http://ipython.scipy.org/dist/ipython-0.8.2.win32-setup.exe
    3. Install Subversion. http://subversion.tigris.org/files/documents/15/41686/svn-1.4.6-setup.exe
    4. Open up a command prompt (Start->Run->cmd). cd to C:\Python25\Lib\site-packages.
    5. Check out the ClearQuest Python library:
    C:\Python25\Lib\site-packages>svn co http://cqpython.googlecode.com/svn/branches/0.9.x/src/clearquest

    Then you can start Python, import the module via 'from clearquest import api', and repeat the same steps above!

    Enjoy!

    Trent.

    --
    http://www.onresolve.com

    _______________________________________________
    clearquest mailing list
    clearquest@lists.ca.ibm.com
    Unsubscribe:clearquest-leave@lists.ca.ibm.com
    Trent,

    That looks like quite the exercise in reverse engineering! Do you have a sample web app implementing this? I'd like to see it as what you have done looks pretty sweet.

    -Sean
  • SystemAdmin
    SystemAdmin
    24948 Posts

    RE: RE: [clearquest] External Script to Submit CR using API

    ‏2008-05-07T19:54:14Z  
    • sgw
    • ‏2008-05-02T18:07:21Z
    Trent,

    That looks like quite the exercise in reverse engineering! Do you have a sample web app implementing this? I'd like to see it as what you have done looks pretty sweet.

    -Sean
    Hi Sean,

    Trent,
    That looks like quite the exercise in reverse engineering!
    Do you have a sample web app implementing this? I'd like to
    see it as what you have done looks pretty sweet.
    -Sean

    Not sure what you mean by a sample web app -- can you clarify what you're looking for? Were you able to download and install the API and have a play around with it?

    Trent.

    _______________________________________________
    clearquest mailing list
    clearquest@lists.ca.ibm.com
    Unsubscribe:clearquest-leave@lists.ca.ibm.com
  • sgw
    sgw
    1003 Posts

    Re: RE: RE: [clearquest] External Script to Submit CR using API

    ‏2008-05-07T21:13:06Z  
    Hi Sean,

    Trent,
    That looks like quite the exercise in reverse engineering!
    Do you have a sample web app implementing this? I'd like to
    see it as what you have done looks pretty sweet.
    -Sean

    Not sure what you mean by a sample web app -- can you clarify what you're looking for? Were you able to download and install the API and have a play around with it?

    Trent.

    _______________________________________________
    clearquest mailing list
    clearquest@lists.ca.ibm.com
    Unsubscribe:clearquest-leave@lists.ca.ibm.com
    Yeah, no problems getting a copy and playing with it, I was just curious if you had any demo app that you were building. I assumed since you were using Genshi that your intention was a web app?

    -Sean