Beanstalk

Version Control with a Human Face

Comment model

Every Changeset in Beanstalk can have many Comments. The API allows you to view and create them.

Writable attributes

  1. body — comment contents;
  2. file_path — file from a diff the comment is associated with;
  3. line_number — line number of the associated file;
  4. revision — changeset revision.

Note on formatting

Beanstalk will automatically escape all HTML tags from the body attribute, apply Textile formatting and turn all URls into clickable HTML links.

Find all comments for a repository

repository_id is required. Either name of the repo or it’s ID can be used. Use page parameter to skim through pages. Beanstalk will send 15 comments per page.

http-request
GET /api/repo_name/comments.xml

Click to expand…

http-response
<?xml version="1.0" encoding="UTF-8"?>
<comments type="array">
  <comment>
    <id type="integer">324934</id>
    <account-id type="integer">4</account-id>
    <author-id type="integer">17</author-id>
    <body>
      Hey, this is my first comment.
      I think you have a typo on this line.
    </body>
    <created-at type="datetime">2010-01-18T15:47:45Z</created-at>
    <file-path>trunk/index.html</file-path>
    <line-number>34</line-number>
    <rendered-body>
      &lt;p&gt;Hey, this is my first comment.
      I think you have a typo on this line.&lt;/p&gt;
    </rendered-body>
    <repository-id type="integer">2</repository-id>
    <revision type="integer">1</revision>
    <updated-at type="datetime">2010-01-18T15:47:45Z</updated-at>
  </comment>
  <comment>
    <id type="integer">834234</id>
    <account-id type="integer">4</account-id>
    <author-id type="integer">17</author-id>
    <body>Check out my *textile* dude.</body>
    <created-at type="datetime">2010-01-18T15:48:54Z</created-at>
    <file-path nil="true"></file-path>
    <line-number nil="true"></line-number>
    <rendered-body>
      &lt;p&gt;Check out my <strong>textile</strong> dude.&lt;/p&gt;
    </rendered-body>
    <repository-id type="integer">2</repository-id>
    <revision type="integer">66</revision>
    <updated-at type="datetime">2010-01-18T15:48:54Z</updated-at>
  </comment>
</comments>
ruby
Beanstalk::API::Comment.find :all, :params => {
  :repository_id => 2
}

Find all comments for specific changeset

http-request
GET /api/repo_name/comments.xml?revision=1

Click to expand…

http-response
<?xml version="1.0" encoding="UTF-8"?>
<comments type="array">
  <comment>
    <id type="integer">583197</id>
    <account-id type="integer">4</account-id>
    <author-id type="integer">17</author-id>
    <body>
      Hey, this is my first comment.
      I think you have a typo on this line.
    </body>
    <created-at type="datetime">2010-01-18T15:47:45Z</created-at>
    <file-path>trunk/index.html</file-path>
    <line-number>34</line-number>
    <rendered-body>
      &lt;p&gt;Hey, this is my first comment.
      I think you have a typo on this line.&lt;/p&gt;
    </rendered-body>
    <repository-id type="integer">2</repository-id>
    <revision type="integer">1</revision>
    <updated-at type="datetime">2010-01-18T15:47:45Z</updated-at>
  </comment>
</comments>
ruby
Beanstalk::API::Comment.find :all, :params => {
  :repository_id => 2,
  :revision => 1
}

Find single comment by id

http-request
GET /api/repo_name/comments/8543.xml

Click to expand…

http-response
<?xml version="1.0" encoding="UTF-8"?>
<comment>
  <id type="integer">8543</id>
  <account-id type="integer">4</account-id>
  <author-id type="integer">17</author-id>
  <body>Hey, this is my first comment.</body>
  <created-at type="datetime">2010-01-18T15:47:45Z</created-at>
  <file-path>trunk/index.html</file-path>
  <line-number>34</line-number>
  <rendered-body>
    &lt;p&gt;Hey, this is my first comment.&lt;/p&gt;
  </rendered-body>
  <repository-id type="integer">2</repository-id>
  <revision type="integer">1</revision>
  <updated-at type="datetime">2010-01-18T15:47:45Z</updated-at>
</comment>
ruby
Beanstalk::API::Comment.find 8543, :params => {
  :repository_id => 2
}

Create new comment

http-request
POST /api/repo_name/comments.xml
<comment>
  <revision type="integer">6</revision>
  <body>This is my comment text.</body>
  <file-path>/branches/application/super_file.txt</file-path>
  <line-number>4</line-number>
</comment>

Click to expand…

http-response
<?xml version="1.0" encoding="UTF-8"?>
<comment>
  <id type="integer">98636</id>
  <account-id type="integer">4</account-id>
  <author-id type="integer">17</author-id>
  <body>This is my comment text.</body>
  <created-at type="datetime">2010-01-18T15:47:45Z</created-at>
  <file-path>/branches/application/super_file.txt</file-path>
  <line-number>4</line-number>
  <rendered-body>
    &lt;p&gt;This is my comment text.&lt;/p&gt;
  </rendered-body>
  <repository-id type="integer">2</repository-id>
  <revision type="integer">6</revision>
  <updated-at type="datetime">2010-01-18T15:47:45Z</updated-at>
</comment>

--OR IF INVALID--

<?xml version="1.0" encoding="UTF-8"?>
<errors>
  <error>Body can't be blank</error>
</errors>
ruby
c = Beanstalk::API::Comment.new
c.prefix_options = { :repository_id => 2 }
c.revision = 6
c.body = "This is my comment text."
c.file_path = "/branches/application/super_file.txt"
c.line_number = 4
c.save